简体   繁体   中英

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.)

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:

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

I have tried the GOT package with a keep-alive config:

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?

What do you want to monitor ? There is a new xhr request every 3 to 5 seconds.

You could intercept xhr requests every time a new .aspx page is received.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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