process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" const {jsdomFromText, browser, jsdomFromUrl} = require("sdenv"); const {Script} = require("vm"); let fs = require('fs'); const cheerio = require('cheerio'); var baseUrl = "https://etax.hubei.chinatax.gov.cn:8443/" let url = `https://etax.hubei.chinatax.gov.cn:8443/`; function loadPages(urlBase64, jsBase64, htmlBase64, cookieBase64, userAgentBase64, ts) { const htmlText = htmlBase64; const jsText = jsBase64; const [jsDom, cookieJar] = jsdomFromText({ proxy: 'http://127.0.0.1:8080', url: url, referrer: url, contentType: "text/html", runScripts: "outside-only", // runScripts: 'dangerously'/'outside-only' }) const dom = jsDom(htmlText); // console.log('file',dom.serialize()) window = dom.window // 加载 window.$_ts let $ = cheerio.load(htmlText); let nextAll = $('script[r=m]'); let trendJs = $('script').first().html(); let js = trendJs + ";\n" + jsText // nextAll.each((index, element) => { // let attr = $(element).html(); // if (attr) { // js += attr // } else { // js += jsText // } // js += ";\n" // }) // fs.writeFileSync('/home/liu/桌面/test111.js', js) cookieJar.setCookieSync(cookieBase64, baseUrl); window.onbeforeunload = async (url) => { const cookies = cookieJar.getCookieStringSync(baseUrl); console.debug(`${url} 生成cookie:`, cookies); let fff = await fetch("https://etax.hubei.chinatax.gov.cn:8443/", { "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", "priority": "u=0, i", "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": "WKFVysqPUWooO=60hpQvjw7ZsGEBT1OJrgQPSqW9IvwKkC7F.ZR1jluU6cX7e7UOWm8eQZB1ZbWnMcg4cEVJcZN9nQtAeSdqDVE_Ea; WKFVysqPUWooP=0MfuEaK_F4sjBozT84fODUBGaz69PKunV0EVKwEm2T2refsm9_SKCDlyB602dwDssmS1E6xPpFjWeYxm.Y1lYG7UhsNpOpuG0XkKH8jySNMcAl8rPBIwAjJ2yjATYrPP8LR__viJamtP2tQ44SVRz1cVIWUN9wPXb8hdLb6_w5WDNz40yGJ8HHlErfshCe_vxWy6QpuT9BDw2Bgzd0d.8HIK9BmcckmPtqXCQE4HvPsPM5bw4.QU.35QlsFl1byPT_A9VIUiohyjHvhfslECM7MXc9JVLUPrpD62nk.qHpI0", "cookie": cookies, "Referer": "https://etax.hubei.chinatax.gov.cn:8443/", "Referrer-Policy": "strict-origin-when-cross-origin" }, "body": null, "method": "GET" }); 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); } async function test() { let response = await fetch(url, {"method": "GET"}); // 返回页面内容 let htmlStr = await response.text(); // console.log(htmlStr) // 页面返回cookie let cookies = response.headers.get("Set-Cookie"); // let htmlCookie = cookies.split('; ')[0]; // console.log(htmlCookie) let staticJs = fs.readFileSync('/home/liu/桌面/hubei.eh5axISchOau.ed63b8f.js'); loadPages(url, staticJs.toString('utf8'), htmlStr, cookies, "") } test();