我可以使用哪种木偶方法来获得网络响应?
答案 0 :(得分:0)
我相信您必须拦截该请求才能获得其响应。
为此,您可以订阅requestfinished
事件,也可以订阅response
事件。
我前一阵子用requestfinished
做过类似的事情,这是要点:
// THIS IS UNTESTED!
page.on('requestfinished', async(request) => {
const response = request.response();
const buffer = await response.buffer(); // Thats the body
const headers = response.headers();
// Look at `headers` to see if it is _the_ request
if (headers.filename.indexOf('Gravatar....') === -1) {
return;
}
console.log(buffer.toString());
});
答案 1 :(得分:0)
page.on('response', async response => {
if(response.url().indexOf('GravarSimulacoesContratoNovo') > -1){
console.log('Response', response.url());
const text = await response.text();
//console.log(text)
//console.log('TEXT:========= GAMBIARRA !!! : ', text[15]+text[16]+text[17]+text[18]+text[19]+text[20]+text[21]+text[22]);
let json_cod = JSON.parse(text)
//console.log('666666666666 = ', json_cod)
console.log('ID DA PROPOSTA ... = ', json_cod[0].IdProposta)
}
// }
}); i finifhed, tanks