Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

40 lines
1.4 KiB
JavaScript

/**
* Weibo hot search — browser cookie API.
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { requireArrayEvaluateResult, unwrapEvaluateResult } from './utils.js';
cli({
site: 'weibo',
name: 'hot',
access: 'read',
description: '微博热搜',
domain: 'weibo.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'limit', type: 'int', default: 30, help: 'Number of items (max 50)' },
],
columns: ['rank', 'word', 'hot_value', 'category', 'label', 'url'],
func: async (page, kwargs) => {
const count = Math.min(kwargs.limit || 30, 50);
await page.goto('https://weibo.com');
const data = requireArrayEvaluateResult(unwrapEvaluateResult(await page.evaluate(`
(async () => {
const resp = await fetch('/ajax/statuses/hot_band', {credentials: 'include'});
if (!resp.ok) return {error: 'HTTP ' + resp.status};
const data = await resp.json();
if (!data.ok) return {error: 'API error'};
const bandList = data.data?.band_list || [];
return bandList.map((item, i) => ({
rank: item.realpos || (i + 1),
word: item.word,
hot_value: item.num || 0,
category: item.category || '',
label: item.label_name || '',
url: 'https://s.weibo.com/weibo?q=' + encodeURIComponent('#' + item.word + '#')
}));
})()
`)), 'weibo hot');
return data.slice(0, count);
},
});