mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): Anti-Anti-Spider 哔哩哔哩,更新 cookie 处理机制 (#12513)
* fix(route): Anti-Anti-Spider 哔哩哔哩,更新 cookie 处理机制 * fix(route): Bilibili use cookieJar to get cookies * fix(route): Anti-Anti-Spider 哔哩哔哩,请求所有视频时区分UA 拉取所有视频需要大量请求分页接口容易被限,修改 User Agent 来跳过标定 * fix(route): remove cookieJar since it is not used in other got requests
This commit is contained in:
@@ -5,8 +5,15 @@ module.exports = {
|
||||
getCookie: (ctx) => {
|
||||
const key = 'bili-cookie';
|
||||
return ctx.cache.tryGet(key, async () => {
|
||||
const response = await got('https://www.bilibili.com/');
|
||||
return response.headers['set-cookie'];
|
||||
// default Referer: https://www.bilibili.com is limited
|
||||
// Bilibili return cookies with multiple set-cookie
|
||||
const url = 'https://www.bilibili.com/';
|
||||
const response = await got(url, {
|
||||
headers: {
|
||||
Referer: url,
|
||||
},
|
||||
});
|
||||
return response.headers['set-cookie'].map((cookie) => cookie.split(';')[0]).join('; ');
|
||||
});
|
||||
},
|
||||
getVerifyString: (ctx) => {
|
||||
|
||||
@@ -2,6 +2,7 @@ const got = require('@/utils/got');
|
||||
const cache = require('./cache');
|
||||
const utils = require('./utils');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const config = require('@/config');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const uid = ctx.params.uid;
|
||||
@@ -28,10 +29,13 @@ module.exports = async (ctx) => {
|
||||
const pageTotal = Math.ceil(response.data.data.page.count / response.data.data.page.ps);
|
||||
|
||||
const getPage = async (pageId) => {
|
||||
// A hack way to skip limit
|
||||
const userAgent = config.ua + `.${pageId}`;
|
||||
await got(`https://space.bilibili.com/${uid}/video?tid=0&page=${pageId}&keyword=&order=pubdate`, {
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
Cookie: cookie,
|
||||
"User-Agent": userAgent
|
||||
},
|
||||
});
|
||||
const params = utils.addVerifyInfo(`mid=${uid}&ps=30&tid=0&pn=${pageId}&keyword=&order=pubdate&platform=web&web_location=1550101&order_avoided=true`, verifyString);
|
||||
@@ -39,6 +43,7 @@ module.exports = async (ctx) => {
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/video?tid=0&page=${pageId}&keyword=&order=pubdate`,
|
||||
Cookie: cookie,
|
||||
"User-Agent": userAgent
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user