You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
5.3 KiB
160 lines
5.3 KiB
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" |
|
|
|
const {jsdomFromText, browser, jsdomFromUrl} = require("sdenv"); |
|
const {Script} = require("vm"); |
|
let fs = require('fs'); |
|
const express = require("express"); |
|
// const cheerio = require('cheerio'); |
|
|
|
|
|
// const app = express(); |
|
|
|
var baseUrl = "https://app.yunnan.chinatax.gov.cn" |
|
let url = `https://app.yunnan.chinatax.gov.cn/xxmh/html/dfts/index_frame.html`; |
|
|
|
// async function extracted(cookieJar) { |
|
// const [jsdomer] = await jsdomFromUrl({ |
|
// // proxy: 'http://127.0.0.1:8080', |
|
// strictSSL: false, |
|
// userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', |
|
// }, cookieJar); |
|
// const dom = await jsdomer(url); |
|
// |
|
// 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; |
|
} |
|
|
|
|
|
async 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://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", { |
|
"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) |
|
} |
|
|
|
|
|
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/桌面/MO5zzCMcub4d.b4c45da.js'); |
|
|
|
await loadPages(url, staticJs.toString('utf8'), htmlStr, cookies, "") |
|
} |
|
|
|
|
|
test();
|
|
|