9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
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
54 lines
2.1 KiB
JavaScript
54 lines
2.1 KiB
JavaScript
/**
|
|
* Weibo comments — get comments on a post.
|
|
*/
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { requireArrayEvaluateResult, unwrapEvaluateResult } from './utils.js';
|
|
cli({
|
|
site: 'weibo',
|
|
name: 'comments',
|
|
access: 'read',
|
|
description: 'Get comments on a Weibo post',
|
|
domain: 'weibo.com',
|
|
strategy: Strategy.COOKIE,
|
|
args: [
|
|
{ name: 'id', required: true, positional: true, help: 'Post ID (numeric idstr)' },
|
|
{ name: 'limit', type: 'int', default: 20, help: 'Number of comments (max 50)' },
|
|
],
|
|
columns: ['rank', 'author', 'text', 'likes', 'replies', 'time'],
|
|
func: async (page, kwargs) => {
|
|
const count = Math.min(kwargs.limit || 20, 50);
|
|
await page.goto('https://weibo.com');
|
|
await page.wait(2);
|
|
const id = String(kwargs.id);
|
|
const data = requireArrayEvaluateResult(unwrapEvaluateResult(await page.evaluate(`
|
|
(async () => {
|
|
const id = ${JSON.stringify(id)};
|
|
const count = ${count};
|
|
const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/ /g, ' ').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').trim();
|
|
|
|
const url = '/ajax/statuses/buildComments?flow=0&is_reload=1&id=' + id + '&is_show_bulletin=2&is_mix=0&count=' + count;
|
|
const resp = await fetch(url, {credentials: 'include'});
|
|
if (!resp.ok) return {error: 'HTTP ' + resp.status};
|
|
const data = await resp.json();
|
|
if (!data.ok) return {error: 'API error: ' + (data.msg || 'unknown')};
|
|
|
|
return (data.data || []).map((c, i) => {
|
|
const item = {
|
|
rank: i + 1,
|
|
author: c.user?.screen_name || '',
|
|
text: strip(c.text || ''),
|
|
likes: c.like_count || 0,
|
|
replies: c.total_number || 0,
|
|
time: c.created_at || '',
|
|
};
|
|
if (c.reply_comment) {
|
|
item.reply_to = (c.reply_comment.user?.screen_name || '') + ': ' + strip(c.reply_comment.text || '').substring(0, 80);
|
|
}
|
|
return item;
|
|
});
|
|
})()
|
|
`)), 'weibo comments');
|
|
return data;
|
|
},
|
|
});
|