繁体   English   中英

如何使用 nodejs 跟踪 .aspx 页面的更改?

[英]how to keep track of changes of an .aspx page using nodejs?

想象一下跟踪这样的页面? (用 Chrome 打开,然后右键单击并选择翻译成英文。)

http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=35366681030756042

当您按 F12 并选择“网络”选项卡时,请注意以大约每秒 1 次的间隔返回响应,其中包含最后的价格和交易,以及这些 HTTP 标头详细信息:

{
   ...
   connection: keep-alive
   cookies: fooCookie
   ...
}

我已经尝试过使用 keep-alive 配置的GOT包:

const gotOption = {
  keepAlive: true,
  maxSockets: 10,
}

await got.get(url, {
        agent: {
          http: new HttpAgent(gotOption),
          https: new HttpsAgent(gotOption),
        },
})

我只得到第一个响应,但我怎样才能得到新的响应? 是否可以为此目的使用 Puppeteer?

你想监控什么? 每 3 到 5 秒有一个新的xhr请求。

每次收到新的.aspx页面时,您都可以拦截xhr请求。

let puppeteer = require(`puppeteer`);
(async () => {
    let browser = await puppeteer.launch({
        headless: true,
    });
    let page = await browser.newPage(); (await browser.pages())[0].close();
    let res = 0;
    page.on('response', async (response) => {    
        if (response.url().includes(`.aspx`)) {
            res++;
            console.log(`\u001b[1;36m` + `Response ${res}: ${new Date(Date.now())}` + `\u001b[0m`);
        };
    }); 
    await page.goto('http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=35366681030756042');
    //await browser.close();
})();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM