【问题标题】:how to keep track of changes of an .aspx page using nodejs?如何使用nodejs跟踪.aspx页面的变化?
【发布时间】:2022-01-25 19:14:31
【问题描述】:

想象跟踪这样的页面? (用 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?

【问题讨论】:

    标签: node.js sockets puppeteer node.js-got


    【解决方案1】:

    嗯,每 3 到 5 秒就会发出一个新的 xhr 请求。

    您可以运行触发该特定事件的函数。拦截.aspx 响应并运行您的脚本。这是一个最小的片段。

    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();
    })();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多