我们可以获取先前调用的HTTP返回代码吗?

时间:2019-03-27 15:44:23

标签: puppeteer

我搜索了文档和网络,但是找不到如何获取查询的HTTP代码。

有人知道吗?

示例:

const puppeteer = require('puppeteer');
const fs = require('fs');
const debug = true;

var base_url = 'https://stackoverflow.com/';

(async () => {
    const browser = await puppeteer.launch({
        headless: true,
    });

    const page = await browser.newPage();
    await page.goto('https://stackoverflow.com');

    // how to get HTTP code of last call ?

    await browser.close();   

})();

response.status(),但不知道如何仅获取上一个查询,并非全部使用

page.on('response', response => {
    console.log("response code: ", response.status());
});

1 个答案:

答案 0 :(得分:1)

好,知道了,谢谢@Take_Care:

response.status()

const puppeteer = require('puppeteer');
const fs = require('fs');
const debug = true;

var base_url = 'https://stackoverflow.com/';

(async () => {
    const browser = await puppeteer.launch({
        headless: true,
    });

    const page = await browser.newPage();
    cons ret = await page.goto('https://stackoverflow.com');

    console.log(ret.status());

    await browser.close();   

})();