我开发了一个基于 Actor+PuppeteerCrawler+Proxy 的爬虫,并希望重新抓取失败的页面。为了增加重新刮擦的机会,我想切换到另一个 proxyUrl。这个想法是,使用修改后的 launchPupperteer 函数和不同的 proxyUrl 创建一个新的爬虫,并重新入队失败的页面。请检查下面的示例代码。
但不幸的是,它不起作用,尽管我通过使用 drop 和重新打开来重置请求队列。是否可以通过使用具有不同 proxyUrl 的 PuppeteerCrawler 来重新抓取失败的页面,以及如何?
最好的问候,沃尔夫冈
for(let retryCount = 0; retryCount <= MAX_RETRY_COUNT; retryCount++){
if(retryCount){
// Try to reset the request queue, so that failed request shell be rescraped
await requestQueue.drop();
requestQueue = await Apify.openRequestQueue(); // this is necessary to avoid exceptions
// Re-enqueue failed urls in array failedUrls >>> ignored although using drop() and reopening request queue!!!
for(let failedUrl of failedUrls){
await requestQueue.addRequest({url: failedUrl});
}
}
crawlerOptions.launchPuppeteerFunction = () => {
return Apify.launchPuppeteer({
// generates a new proxy url and adds it to a new launchPuppeteer function
proxyUrl: createProxyUrl()
});
};
let crawler = new Apify.PuppeteerCrawler(crawlerOptions);
await crawler.run();
}