本文介绍了Puppeteer:如何听取具体的回应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在修改名为 puppeteer
的无头 chrome 节点 API.
I'm tinkering with the headless chrome node api called puppeteer
.
我想知道如何听取特定的请求响应以及如何采取相应的行动.
I'm wondering how to listen to a specific request response and how to act in consequence.
我查看了事件 requestfinish
和 response
但它给了我所有页面中已经执行的请求/响应.
I have look at events requestfinish
and response
but it gives me all the request/responses already performed in the page.
如何实现评论行为?
谢谢!
推荐答案
一种选择是执行以下操作:
One option is to do the following:
page.on('response', response => {
if (response.url().endsWith("your/match"))
console.log("response code: ", response.status());
// do something here
});
这仍然会捕获所有请求,但允许您过滤事件发射器并对其进行操作.
This still catches all requests, but allows you to filter and act on the event emitter.
https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#event-response
这篇关于Puppeteer:如何听取具体的回应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!