如何阻止木偶跟随重定向 [英] How to stop puppeteer follow redirects
本文介绍了如何阻止木偶跟随重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前看来,操纵up的默认行为是跟随重定向并在链的末尾返回DOM.
Currently it seems the default behaviour of puppeteer is to follow redirects and return the DOM at the end of the chain.
在第一次重定向发生后,如何使 .goto()
方法停止并在我调用page.content()方法时简单地从该第一个3xx页面返回html?
How can I make the .goto()
method to stop after the first redirect happened and simply return the html from that first 3xx page when i call page.content() method?
推荐答案
如果标识了一系列请求,则可以启用请求拦截并中止其他请求:
You can enable a request interception and abort additional requests if a chain of requests is identified:
await page.setRequestInterception(true);
page.on('request', request => {
if (request.isNavigationRequest() && request.redirectChain().length !== 0) {
request.abort();
} else {
request.continue();
}
});
await page.goto('https://www.example.com/');
这篇关于如何阻止木偶跟随重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文