30 lines
1.3 KiB
JavaScript
30 lines
1.3 KiB
JavaScript
// 通过常驻桥查询评论管理页,抓评论列表接口
|
|
import { evalViaBridge, health } from './client.mjs';
|
|
import fs from 'node:fs';
|
|
|
|
console.log('health=' + JSON.stringify(await health()));
|
|
|
|
// 装钩子并导航到评论管理页
|
|
await evalViaBridge(`(() => {
|
|
window.__CAP = [];
|
|
const oOpen = XMLHttpRequest.prototype.open;
|
|
const oSend = XMLHttpRequest.prototype.send;
|
|
XMLHttpRequest.prototype.open = function(m,u){ this.__u=u; return oOpen.apply(this,arguments); };
|
|
XMLHttpRequest.prototype.send = function(){
|
|
this.addEventListener('load', () => {
|
|
try { const ct=this.getResponseHeader('content-type')||''; if(ct.includes('json') && this.responseText) window.__CAP.push({url:this.__u, body:this.responseText.slice(0,400000)}); } catch(e){}
|
|
});
|
|
return oSend.apply(this,arguments);
|
|
};
|
|
return 'hooked';
|
|
})()`);
|
|
|
|
await evalViaBridge(`location.href='https://baijiahao.baidu.com/builder/rc/commentmanage/comment/all'`);
|
|
await new Promise(r => setTimeout(r, 12000));
|
|
|
|
const cap = await evalViaBridge(`(window.__CAP||[]).map(x=>({url:x.url, body:x.body}))`);
|
|
fs.writeFileSync('out/comment-capture.json', JSON.stringify(cap, null, 2), 'utf8');
|
|
console.log('CAP=' + (cap || []).length);
|
|
for (const c of cap || []) console.log('API ' + String(c.url).slice(0, 170));
|
|
process.exit(0);
|