/
sogou.ts
77 lines (71 loc) · 2.12 KB
/
sogou.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
const host = 'https://weixin.sogou.com';
import { finishArticleItem } from '@/utils/wechat-mp';
export const route: Route = {
path: '/sogou/:id',
categories: ['new-media'],
example: '/wechat/sogou/qimao0908',
parameters: { id: '公众号 id, 打开 weixin.sogou.com 并搜索相应公众号, 在 URL 中找到 id' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '公众号(搜狗来源)',
maintainers: ['EthanWng97'],
handler,
};
async function handler(ctx) {
const wechatId = ctx.req.param('id');
let url = `${host}/weixin`;
let response = await got({
method: 'get',
url,
searchParams: {
query: wechatId,
},
});
let $ = load(response.data);
const href = $('a[uigs="account_article_0"]').attr('href');
const title = $('a[uigs="account_name_0"]').text();
url = `${host}${href}`;
response = await got({
url,
method: 'get',
headers: {
Cookie: 'SNUID=78725B470A0EF2C3F97AA5EB0BBF95C1; ABTEST=0|1680917938|v1; SUID=8F7B1C682B83A20A000000006430C5B2; PHPSESSID=le2lak0vghad5c98ijd3t51ls4; IPLOC=USUS5',
},
});
$ = load(response.data);
const jsCode = $('script').text();
const regex = /url \+= '([^']+)';/g;
const matches = [];
let match;
while ((match = regex.exec(jsCode)) !== null) {
matches.push(match[1]);
}
let link = '';
if (matches.length > 0) {
link = matches
.join('')
.replaceAll(/(\r\n|\n|\r)/gm, '') // remove newlines
.replaceAll(' ', ''); // remove spaces
url = url.replace('@', '');
}
const item = {
link,
guid: link,
};
await finishArticleItem(item);
return {
title: `${title} 的微信公众号`,
link: url,
description: `${title} 的微信公众号`,
item: [item],
};
}