相关疑难解决方法(0)

如何使用 Puppeteer 从 XHR 请求中获取 body / json 响应

我想从我用 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()); 
        } 
    }); 
})()
Run Code Online (Sandbox Code Playgroud)

这只是返回一个承诺挂起函数。任何帮助都会很棒。

javascript webautomation node.js puppeteer

15
推荐指数
1
解决办法
2万
查看次数

Puppeteer:如何听取具体的回应?

我正在修补无头镀铬节点api puppeteer.

我想知道如何倾听特定的请求响应以及如何采取行动.

我查看了事件requestfinish,response但它给了我在页面中已经执行的所有请求/响应.

我怎样才能实现评论行为?

谢谢 !

node.js puppeteer

7
推荐指数
3
解决办法
9587
查看次数

标签 统计

node.js ×2

puppeteer ×2

javascript ×1

webautomation ×1