我搜索了文档和网络,但是找不到如何获取查询的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());
});
答案 0 :(得分:1)
好,知道了,谢谢@Take_Care:
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();
})();