我登录到一个网站,它会给我一个浏览器cookie。
我转到一个url,它是一个json响应。
如何在输入await page.goto('blahblahblah.json');
是吗?

最佳答案

另一种不给您intermittent issues的方法是在主体可用时对其求值,并将其作为json返回。

const puppeteer = require('puppeteer');

async function run() {

    const browser = await puppeteer.launch( {
        headless: false  //change to true in prod!
    });

    const page = await browser.newPage();

    await page.goto('https://raw.githubusercontent.com/GoogleChrome/puppeteer/master/package.json');

    var content = await page.content();

    innerText = await page.evaluate(() =>  {
        return JSON.parse(document.querySelector("body").innerText);
    });

    console.log("innerText now contains the JSON");
    console.log(innerText);

    //I will leave this as an excercise for you to
    //  write out to FS...

    await browser.close();

};

run();

07-28 11:46
查看更多