/ clis / nowcoder / salary.js
salary.js
 1  import { cli } from '@jackwener/opencli/registry';
 2  
 3  cli({
 4      site: 'nowcoder',
 5      name: 'salary',
 6      description: 'Salary disclosure posts',
 7      domain: 'www.nowcoder.com',
 8      args: [
 9          { name: 'page', type: 'int', default: 1, help: 'Page number' },
10          { name: 'limit', type: 'int', default: 15, help: 'Number of items' },
11      ],
12      columns: ['rank', 'title', 'author', 'school', 'likes', 'comments', 'views', 'id'],
13      pipeline: [
14          { navigate: 'https://www.nowcoder.com' },
15          { evaluate: `(async () => {
16    const page = \${{ args.page }};
17    const limit = \${{ args.limit }};
18    const r = await fetch('https://gw-c.nowcoder.com/api/sparta/home/tab/content?tabId=858&categoryType=1&pageNo=' + page + '&pageSize=' + limit, {credentials: 'include'});
19    const d = await r.json();
20    if (!d.success) throw new Error(d.msg || 'API failed');
21    return (d.data?.records || []).map((item, i) => {
22      const moment = item.momentData || {};
23      const content = item.contentData || {};
24      return {
25        rank: i + 1,
26        title: moment.title || content.title || '',
27        author: item.userBrief?.nickname || '',
28        school: item.userBrief?.educationInfo || '',
29        likes: item.frequencyData?.likeCnt || 0,
30        comments: item.frequencyData?.commentCnt || 0,
31        views: item.frequencyData?.viewCnt || 0,
32        id: moment.uuid || content.uuid || item.contentId || '',
33      };
34    });
35  })()
36  ` },
37          { filter: 'item.title' },
38          { limit: '${{ args.limit }}' },
39      ],
40  });