fix: hhgal needs to bypass YunSuoAutoJump (#4382)
This commit is contained in:
parent
58a0db57d6
commit
6ddeb99ebd
|
|
@ -1,14 +1,42 @@
|
|||
const cheerio = require('cheerio');
|
||||
const cloudscraper = require('cloudscraper');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const browser = await require('@/utils/puppeteer')();
|
||||
const page = await browser.newPage();
|
||||
await page.goto('https://www.hhgal.com/');
|
||||
const htmlHandle = await page.$('html');
|
||||
const html = await page.evaluate((html) => html.innerHTML, htmlHandle);
|
||||
browser.close();
|
||||
const baseUrl = 'https://www.hhgal.com/';
|
||||
const stringToHex = (str) => {
|
||||
let val = '';
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
if (val === '') {
|
||||
val = str.charCodeAt(i).toString(16);
|
||||
} else {
|
||||
val += str.charCodeAt(i).toString(16);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
const jar = cloudscraper.jar();
|
||||
const response = await cloudscraper({
|
||||
uri: baseUrl,
|
||||
jar: jar,
|
||||
});
|
||||
let html = null;
|
||||
|
||||
if (response.indexOf('YunSuoAutoJump') > -1) {
|
||||
const screenData = stringToHex('1280,720');
|
||||
const urlData = stringToHex(baseUrl);
|
||||
jar.setCookie('srcurl=' + urlData, baseUrl);
|
||||
await cloudscraper({
|
||||
uri: baseUrl + '?security_verify_data=' + screenData,
|
||||
jar: jar,
|
||||
});
|
||||
html = await cloudscraper({
|
||||
uri: baseUrl,
|
||||
jar: jar,
|
||||
});
|
||||
}
|
||||
|
||||
const $ = html === null ? cheerio.load(response) : cheerio.load(html);
|
||||
const list = $('#article-list').find('.article');
|
||||
|
||||
ctx.state.data = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue