fix: hhgal needs to bypass YunSuoAutoJump (#4382)

This commit is contained in:
kotoyuuko 2020-04-13 19:51:43 +08:00 committed by GitHub
parent 58a0db57d6
commit 6ddeb99ebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 7 deletions

View File

@ -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 = {