forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ethan Shen
authored
Jul 17, 2021
1 parent
53472e7
commit 0f4efa8
Showing
1 changed file
with
25 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
|
||
module.exports = async (ctx) => { | ||
const uid = ctx.params.uid; | ||
|
||
const rootUrl = 'https://tieba.baidu.com'; | ||
const userUrl = `${rootUrl}/home/get/getthread?un=${uid}&pn=1&ie=utf8`; | ||
const response = await got({ | ||
method: 'get', | ||
url: userUrl, | ||
url: `https://tieba.baidu.com/home/main?un=${uid}`, | ||
}); | ||
|
||
const data = response.data; | ||
|
||
const $ = cheerio.load(data); | ||
const name = $('span.userinfo_username').text(); | ||
const list = $('div.n_right.clearfix'); | ||
let imgurl; | ||
|
||
ctx.state.data = { | ||
title: `${uid}的贴子 - 百度贴吧`, | ||
link: `${rootUrl}/home/main?un=${uid}`, | ||
item: response.data.data.thread_list.map((item) => { | ||
let media = ''; | ||
if (item.media) { | ||
for (const m of item.media) { | ||
media += `<img src="${m.big_pic}">`; | ||
} | ||
} | ||
return { | ||
title: item.title, | ||
description: `<p>${item.content}</p>${media}`, | ||
pubDate: new Date(item.create_time * 1000).toUTCString(), | ||
link: `https://tieba.baidu.com/p/${item.thread_id}?pid=${item.post_id}&cid=#${item.post_id}`, | ||
}; | ||
}), | ||
title: `${name} 的贴吧`, | ||
link: `https://tieba.baidu.com/home/main?un=${uid}`, | ||
item: | ||
list && | ||
list | ||
.map((index, item) => { | ||
item = $(item).find('.n_contain'); | ||
imgurl = item.find('ul.n_media.clearfix img').attr('original'); | ||
return { | ||
title: item.find('div.thread_name a').attr('title'), | ||
pubDate: Date.parse(item.parent().find('div .n_post_time').text()), | ||
description: `${item.find('div.n_txt').text()}<br><img src="${imgurl}">`, | ||
link: item.find('div.thread_name a').attr('href'), | ||
}; | ||
}) | ||
.get(), | ||
}; | ||
}; |