简体   繁体   中英

Get responses from multiple requests that where triggered by an initial http request

I'm making a Javascript program that receives a URL and get the responses that requests triggered by the initial URL returned. I'm using fetch api for the http request.

When I enter a url in Chrome and open the Network tab of the devtools I get the following request with their respective responses:

在此处输入图像描述

Now, my target is to get the json objects that I get from those requests (from survey_data, survey_metadata and translations) while given the initial URL.

Is there any way I can get those json objects or those URL addresses for making a new fetch request with this URL's?

Thank you all.

Problem solved. I have done this using puppeteer. The browser.interceptRequest() did the job by intercepting the requests of a given URL (rootUrl), and then getting those URL's.

const getAllUrls = async (rootUrl) => {
const puppeteer = require('puppeteer');
const urls = [];
await puppeteer.launch().then(async browser => {
    const page = await browser.newPage();
    await page.setRequestInterception(true);
    page.on('request', interceptedRequest => {
        if (isRelevantUrl(interceptedRequest.url())) {
            urls.push(interceptedRequest.url());
            interceptedRequest.abort();
        } else {
            interceptedRequest.continue();
        }
    });
    await page.goto(rootUrl);
    await browser.close()
})
.catch(err => console.log(err));

return urls; 

}

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