page.on('response', (response) => {
if (response.url().endsWith(url)&&response.request()._method === method) {
response.json()
}
})
如何在page.on外部使用response.json()
进行下一步操作,因为如果将代码包装在promise中,由于page.on内部循环,所有步骤都会卡住
答案 0 :(得分:0)
async getResponse(url, method, responseBody) {
const page = this.helpers['Puppeteer'].page;
page.on('response', async (response) => {
if ((await response.url()).endsWith(url)&&response. _request._method === method) {
responseBody.push(await response.json());
}
});
}
只需要在getResonse之前声明变量并使用它即可
让响应= [] getResponse(URL,方法,响应)