我想从使用 Puppeteer 抓取的网站获取 JSON 数据,但我不知道如何取回请求正文。这是我尝试过的:
const puppeteer = require('puppeteer')
const results = [];
(async () => {
const browser = await puppeteer.launch({
headless: false
})
const page = await browser.newPage()
await page.goto("https://capuk.org/i-want-help/courses/cap-money-course/introduction", {
waitUntil: 'networkidle2'
});
await page.type('#search-form > input[type="text"]', 'bd14ew')
await page.click('#search-form > input[type="submit"]')
await page.on('response', response => {
if (response.url() == "https://capuk.org/ajax_search/capmoneycourses"){
console.log('XHR response received');
console.log(response.json());
}
});
})()
这只是返回一个承诺待处理函数。任何帮助都会很棒。
As response.json
返回一个我们需要等待的承诺。
page.on('response', async (response) => {
if (response.url() == "https://capuk.org/ajax_search/capmoneycourses"){
console.log('XHR response received');
console.log(await response.json());
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)