master
刘东琪 9 months ago
parent 57c4721dab
commit f9114990e0
  1. 38
      routes/index.js
  2. 103
      test/rs6/yunnan.js

@ -21,7 +21,7 @@ router.post('/rsCookie', async (req, res) => {
let cookie = req.body['cookieBase64']; let cookie = req.body['cookieBase64'];
let userAgent = req.body['userAgentBase64']; let userAgent = req.body['userAgentBase64'];
console.log(`${uuid};接收到 ${areaName} 请求:${url}`) console.log(`${uuid};接收到 ${areaName} 请求:${url}`)
fs.writeFileSync(`./back/${uuid}.url`, `${url}\n ${userAgent}\n ${cookie} \n`); // fs.writeFileSync(`./back/${uuid}.url`, `${url}\n ${userAgent}\n ${cookie} \n`);
if (url == null || url === '') { if (url == null || url === '') {
return res.status(500).send('error url') return res.status(500).send('error url')
} }
@ -105,22 +105,29 @@ async function handle(url, htmlStr, jsText, cookie, userAgent, uuid, loadHtmlJs)
if (cookie != null) { if (cookie != null) {
let cookieList = CookieStr2List(cookie); let cookieList = CookieStr2List(cookie);
console.log(`${uuid};cookie 加载长度--->`, cookieList, baseUrl) console.log(`${uuid};cookie 加载长度--->`, cookieList, baseUrl)
fs.writeFileSync(`./back/${uuid}.cookie`, cookie) // fs.writeFileSync(`./back/${uuid}.cookie`, cookie)
for (let i = 0; i < cookieList.length; i++) { for (let i = 0; i < cookieList.length; i++) {
cookieJar.setCookieSync(cookieList[i], baseUrl); cookieJar.setCookieSync(cookieList[i], baseUrl);
} }
} }
// 设置cookie的回掉
const superSetCookie = cookieJar.setCookie;
cookieJar.setCookie = function (cookie, currentUrl, options, callback) {
console.log(`${uuid};正在设置 Cookie:`, cookie, currentUrl);
// store.set(uuid, cookie)
return superSetCookie.call(this, cookie, currentUrl, options, callback);
};
// 加载dom // 加载dom
let dom = await jsDom(htmlStr); let dom = await jsDom(htmlStr);
// console.log('html 加载长度--->', dom.serialize()) // console.log('html 加载长度--->', dom.serialize())
console.log(`${uuid};html 加载长度--->`, dom.serialize().length) console.log(`${uuid};html 加载长度--->`, dom.serialize().length)
fs.writeFileSync(`./back/${uuid}.html`, dom.serialize()) // fs.writeFileSync(`./back/${uuid}.html`, dom.serialize())
window = dom.window window = dom.window
// js执行成功后的瑞树会跳转页面 会触发onbeforeunload钩子 // js执行成功后会跳转页面 会触发onbeforeunload钩子
window.onbeforeunload = async (url) => { window.onbeforeunload = async (url) => {
const cookies = cookieJar.getCookieStringSync(baseUrl); const cookies = cookieJar.getCookieStringSync(baseUrl);
// console.debug(`${url} 生成cookie:`, cookies); console.debug(`${url} 生成cookie:`, cookies);
store.set(uuid, cookies) store.set(uuid, cookies)
// window.close(); // window.close();
} }
@ -134,33 +141,24 @@ async function handle(url, htmlStr, jsText, cookie, userAgent, uuid, loadHtmlJs)
js = jsText; js = jsText;
} }
console.log(`${uuid};js 加载长度--->`, js.length) console.log(`${uuid};js 加载长度--->`, js.length)
fs.writeFileSync(`./back/${uuid}.js`, js) // fs.writeFileSync(`./back/${uuid}.js`, js)
// 执行 js // 执行 js
let script = new Script(js); let script = new Script(js);
let internalVMContext = dom.getInternalVMContext(); let internalVMContext = dom.getInternalVMContext();
script.runInContext(internalVMContext); script.runInContext(internalVMContext);
// 等待 onbeforeunload 钩子触发后的回掉 // 等待 onbeforeunload 钩子触发后的回掉
let timeout = -1; // let val = await store.waitGetAndDelete(uuid, 100, 10)
let reTry = -1;
if (process.env.NODE_ENV === 'prod') {
timeout = 100
reTry = 10
} else {
timeout = 100
reTry = 10
}
let val = await store.waitGetAndDelete(uuid, timeout, reTry)
// bug 关闭后 部分参数是需要永久保存在内存中的 比如 cookie 实例 下次调用会报错 // bug 关闭后 部分参数是需要永久保存在内存中的 比如 cookie 实例 下次调用会报错
// internalVMContext.close() // internalVMContext.close()
// window.close() // window.close()
// dom = null // dom = null
if (val != null) { // if (val != null) {
return val; // return val;
} // }
console.log(`${uuid} 执行超时`) // console.log(`${uuid} 执行超时`)
return cookieJar.getCookieStringSync(baseUrl); return cookieJar.getCookieStringSync(baseUrl);
// throw new Error(`${uuid}执行超时`) // throw new Error(`${uuid}执行超时`)
} }

@ -4,32 +4,49 @@ const {jsdomFromText, browser, jsdomFromUrl} = require("sdenv");
const {Script} = require("vm"); const {Script} = require("vm");
let fs = require('fs'); let fs = require('fs');
const express = require("express"); const express = require("express");
const cheerio = require('cheerio'); // const cheerio = require('cheerio');
const app = express(); // const app = express();
var baseUrl = "https://app.yunnan.chinatax.gov.cn" var baseUrl = "https://app.yunnan.chinatax.gov.cn"
let url = `https://app.yunnan.chinatax.gov.cn/xxmh/html/dfts/index_frame.html`; let url = `https://app.yunnan.chinatax.gov.cn/xxmh/html/dfts/index_frame.html`;
async function extracted(cookieJar) { // async function extracted(cookieJar) {
const [jsdomer] = await jsdomFromUrl({ // const [jsdomer] = await jsdomFromUrl({
proxy: 'http://127.0.0.1:8080', // // proxy: 'http://127.0.0.1:8080',
strictSSL: false, // strictSSL: false,
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', // userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
}, cookieJar); // }, cookieJar);
const dom = await jsdomer(url); // const dom = await jsdomer(url);
//
console.log(dom.serialize()) // console.log(dom.serialize())
// }
function loadJs(window, jsText) {
// 加载js
let js = '';
// 加载 页面上的js
const allScript = window.document.querySelectorAll('script[r="m"]');
for (let i = 0; i < allScript.length; i++) {
const script = allScript[i];
let attr = script.textContent;
if (attr) {
js += attr
} else {
js += jsText
}
js += ";\n"
}
return js;
} }
function loadPages(urlBase64, jsBase64, htmlBase64, cookieBase64, userAgentBase64, ts) { async function loadPages(urlBase64, jsBase64, htmlBase64, cookieBase64, userAgentBase64, ts) {
const htmlText = htmlBase64; const htmlText = htmlBase64;
const jsText = jsBase64; const jsText = jsBase64;
const [jsDom, cookieJar] = jsdomFromText({ const [jsDom, cookieJar] = jsdomFromText({
proxy: 'http://127.0.0.1:8080', // proxy: 'http://127.0.0.1:8080',
url: url, url: url,
referrer: url, referrer: url,
contentType: "text/html", contentType: "text/html",
@ -41,11 +58,11 @@ function loadPages(urlBase64, jsBase64, htmlBase64, cookieBase64, userAgentBase6
window = dom.window window = dom.window
// 加载 window.$_ts // 加载 window.$_ts
let $ = cheerio.load(htmlText); // let $ = cheerio.load(htmlText);
let nextAll = $('script[r=m]'); // let nextAll = $('script[r=m]');
let trendJs = $('script').first().html(); // let trendJs = $('script').first().html();
let js = trendJs + ";\n" + jsText // let js = trendJs + ";\n" + jsText
// nextAll.each((index, element) => { // nextAll.each((index, element) => {
// let attr = $(element).html(); // let attr = $(element).html();
// if (attr) { // if (attr) {
@ -59,13 +76,47 @@ function loadPages(urlBase64, jsBase64, htmlBase64, cookieBase64, userAgentBase6
cookieJar.setCookieSync(cookieBase64, baseUrl); cookieJar.setCookieSync(cookieBase64, baseUrl);
window.onbeforeunload = async (url) => { window.onbeforeunload = async (url) => {
const cookies = cookieJar.getCookieStringSync(baseUrl); const cookies = cookieJar.getCookieStringSync(baseUrl);
console.debug(`${url} 生成cookie:`, cookies); console.debug(`${url} 生成cookie:`, cookies);
// let fff = await fetch("https://app.yunnan.chinatax.gov.cn/xxmh/html/dfts/index_frame.html", {
// "headers": {
// "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
// "accept-language": "zh-CN,zh;q=0.9",
// "cache-control": "no-cache",
// "pragma": "no-cache",
// "sec-ch-ua": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"",
// "sec-ch-ua-mobile": "?0",
// "sec-ch-ua-platform": "\"Linux\"",
// "sec-fetch-dest": "document",
// "sec-fetch-mode": "navigate",
// "sec-fetch-site": "same-origin",
// "upgrade-insecure-requests": "1",
// "cookie": cookies,
// "Referer": "https://app.yunnan.chinatax.gov.cn/xxmh/html/dfts/index_frame.html",
// }, "body": null, "method": "GET"
// });
//
// console.log(fff.status, fff.statusText)
window.close();
}
browser(dom.window, 'chrome');
let js = loadJs(window, jsText);
let script = new Script(js);
let internalVMContext = dom.getInternalVMContext();
// 执行 js
script.runInContext(internalVMContext);
const cookies = cookieJar.getCookieStringSync(baseUrl);
let fff = await fetch("https://app.yunnan.chinatax.gov.cn/xxmh/html/dfts/index_frame.html", { let fff = await fetch("https://app.yunnan.chinatax.gov.cn/xxmh/html/dfts/index_frame.html", {
"headers": { "headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
@ -85,18 +136,6 @@ function loadPages(urlBase64, jsBase64, htmlBase64, cookieBase64, userAgentBase6
}); });
console.log(fff.status, fff.statusText) console.log(fff.status, fff.statusText)
window.close();
}
browser(dom.window, 'chrome');
let script = new Script(js);
let internalVMContext = dom.getInternalVMContext();
// 执行 js
script.runInContext(internalVMContext);
} }
@ -104,7 +143,7 @@ async function test() {
let response = await fetch(url, {"method": "GET"}); let response = await fetch(url, {"method": "GET"});
// 返回页面内容 // 返回页面内容
let htmlStr = await response.text(); let htmlStr = await response.text();
// console.log(htmlStr) console.log(htmlStr)
// 页面返回cookie // 页面返回cookie
@ -114,7 +153,7 @@ async function test() {
let staticJs = fs.readFileSync('/home/liu/桌面/MO5zzCMcub4d.b4c45da.js'); let staticJs = fs.readFileSync('/home/liu/桌面/MO5zzCMcub4d.b4c45da.js');
loadPages(url, staticJs.toString('utf8'), htmlStr, cookies, "") await loadPages(url, staticJs.toString('utf8'), htmlStr, cookies, "")
} }

Loading…
Cancel
Save