forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
59 lines (57 loc) · 1.57 KB
/
user.js
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
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const config = require('../../config');
const baseUrl = 'https://toutiao.io';
module.exports = async (ctx) => {
const id = ctx.params.id;
const requestUrl = `${baseUrl}/subjects/${id}?f=new`;
const response = await axios({
method: 'get',
url: requestUrl,
headers: {
'User-Agent': config.ua,
Host: 'toutiao.io',
},
responseType: 'text',
});
const $ = cheerio.load(response.data);
const image = $('#main')
.find('.text-center>.subject-cover>img')
.eq(0)
.attr('src');
const title = $('#main')
.find('.text-center>h3')
.eq(0)
.text();
const description = $('#main')
.find('.social-share-button')
.eq(0)
.attr('data-title');
const list = $('.posts>.post', '#main');
const article_item = [];
for (let i = 0; i < list.length; i++) {
const article_el = $(list[i])
.find('.content')
.eq(0);
const item = {
title: article_el
.find('a')
.eq(0)
.text(),
link:
baseUrl +
article_el
.find('a')
.eq(0)
.attr('href'),
};
article_item.push(item);
}
ctx.state.data = {
title: '开发者头条独家号:' + title,
description: description,
image: image,
link: baseUrl,
item: article_item,
};
};