简体   繁体   English

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

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

Imagine keeping track of a page like this?想象一下跟踪这样的页面? (Open with Chrome, then right click and select Translate to English.) (用 Chrome 打开,然后右键单击并选择翻译成英文。)

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

When you press F12 and select the Network tab, note that responses are returning—with an interval of about 1 per second—containing the last prices and trades, with these HTTP header details:当您按 F12 并选择“网络”选项卡时,请注意以大约每秒 1 次的间隔返回响应,其中包含最后的价格和交易,以及这些 HTTP 标头详细信息:

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

I have tried the GOT package with a keep-alive config:我已经尝试过使用 keep-alive 配置的GOT包:

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

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

I get just the first response, but how can I get new responses?我只得到第一个响应,但我怎样才能得到新的响应? Is it possible to use Puppeteer for this purpose?是否可以为此目的使用 Puppeteer?

What do you want to monitor ?你想监控什么? There is a new xhr request every 3 to 5 seconds.每 3 到 5 秒有一个新的xhr请求。

You could intercept xhr requests every time a new .aspx page is received.每次收到新的.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