9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
64 lines
2.5 KiB
JavaScript
64 lines
2.5 KiB
JavaScript
/**
|
|
* Weibo user — get user profile by uid or screen_name.
|
|
*/
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { CommandExecutionError } from '@jackwener/opencli/errors';
|
|
import { requireObjectEvaluateResult, unwrapEvaluateResult } from './utils.js';
|
|
cli({
|
|
site: 'weibo',
|
|
name: 'user',
|
|
access: 'read',
|
|
description: 'Get Weibo user profile',
|
|
domain: 'weibo.com',
|
|
strategy: Strategy.COOKIE,
|
|
args: [
|
|
{ name: 'id', required: true, positional: true, help: 'User ID (numeric uid) or screen name' },
|
|
],
|
|
columns: ['screen_name', 'uid', 'followers', 'following', 'statuses', 'verified', 'description', 'location', 'url'],
|
|
func: async (page, kwargs) => {
|
|
await page.goto('https://weibo.com');
|
|
await page.wait(2);
|
|
const id = String(kwargs.id);
|
|
const data = requireObjectEvaluateResult(unwrapEvaluateResult(await page.evaluate(`
|
|
(async () => {
|
|
const id = ${JSON.stringify(id)};
|
|
const isUid = /^\\d+$/.test(id);
|
|
const query = isUid ? 'uid=' + id : 'screen_name=' + encodeURIComponent(id);
|
|
|
|
const resp = await fetch('/ajax/profile/info?' + query, {credentials: 'include'});
|
|
if (!resp.ok) return {error: 'HTTP ' + resp.status};
|
|
const data = await resp.json();
|
|
if (!data.ok || !data.data?.user) return {error: 'User not found'};
|
|
|
|
const u = data.data.user;
|
|
|
|
// Fetch detail info
|
|
const detailResp = await fetch('/ajax/profile/detail?uid=' + u.id, {credentials: 'include'});
|
|
const detail = detailResp.ok ? await detailResp.json() : null;
|
|
const d = detail?.data || {};
|
|
|
|
return {
|
|
screen_name: u.screen_name,
|
|
uid: u.id,
|
|
followers: u.followers_count,
|
|
following: u.friends_count,
|
|
statuses: u.statuses_count,
|
|
verified: u.verified || false,
|
|
verified_reason: u.verified_reason || '',
|
|
description: u.description || d.description || '',
|
|
location: u.location || '',
|
|
gender: u.gender === 'm' ? 'male' : u.gender === 'f' ? 'female' : '',
|
|
avatar: u.avatar_hd || u.avatar_large || '',
|
|
url: 'https://weibo.com' + (u.profile_url || '/u/' + u.id),
|
|
birthday: d.birthday || '',
|
|
created_at: d.created_at || '',
|
|
ip_location: d.ip_location || '',
|
|
};
|
|
})()
|
|
`)), 'weibo user');
|
|
if (data.error)
|
|
throw new CommandExecutionError(String(data.error));
|
|
return data;
|
|
},
|
|
});
|