sdenv獲取瑞數6后綴
使用草木一秋大佬的項目:https://github.com/pysunday/sdenv
孿生項目:https://github.com/pysunday/rs-reverse
本人使用的是docker映射本地文件的方式在Linux運行
主要邏輯:
- 在加載網頁內部js(瑞數初始化)前重寫open,因為瑞數js關于后綴的open是已經重寫的,所以要在瑞數重寫open之前重寫open
- 瑞數初始化以后,再手動發起請求
步驟:
- 將項目克隆到Linux,cd進入sdenv
- 修改/example/use-remote/index.js
?重寫loadPagesSecond
const {window, sdenv} = await jsdomFromUrl(url, {
cookieJar,
userAgent,
consoleConfig: {error: new Function},
});
/*
=== 重寫 XMLHttpRequest,只攔截,不請求 ===
因為瑞數后綴是重寫了open,所以要在瑞數重寫之前重寫open
*/
const originalOpen = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function (method, requestUrl, async, user, password) {
this._requestUrl = requestUrl;
this._method = method;
// 關鍵:徹底阻止 send,替換為空函數
this.send = function (body) {
logger.info(`[攔截成功] URL: ${this._requestUrl}`);
// 模擬一個“完成”狀態,防止頁面卡死
setTimeout(() => {
this.readyState = 4;
this.status = 0; // 或 200,取決于想模擬什么
if (this.onreadystatechange) {
this.onreadystatechange();
}
}, 0);
};
return originalOpen.call(this, method, requestUrl, async, user, password);
};
?新增手動發送請求代碼(只獲取URL,不發送請求),借鑒了草木一秋大佬的代碼
// 手動發起請求 xhr 觸發重寫的 open 和 send
const xhr = new window.XMLHttpRequest();
xhr.open("POST", 'http://epub.cnipa.gov.cn/Dxb/PageQuery', false);
xhr.setRequestHeader('Accept', 'application/json');
xhr.onreadystatechange = function () {
// 此時的responseURL和responseText應該都為空,因為已經被重寫的open攔截
logger.debug("url:", xhr.responseURL);
logger.debug("responseText:", xhr.responseText);
// 狀態變化: 1 0 1是被攔截,4是未攔截
logger.debug('狀態變化:', xhr.readyState, xhr.status);
};
try {
xhr.send(); // 觸發定義的日志
} catch (e) {
logger.error('發送請求失敗:', e);
}
- docker運行
docker run --rm -v $(pwd)/example/use-remote:/app crpi-vkjftqt0qsdk2jmc.cn-shanghai.personal.cr.aliyuncs.com/pysunday/sdenv-x86_64:1.0.0 /app/index.js


浙公網安備 33010602011771號