我通过使用PuppeteerCrawler开发了一种抓取行为,目前已启用。和最大并发1,我有几个问题:
最佳成绩, Wulfgääng
答案 0 :(得分:2)
首先,您不需要将maxConcurrency设置为1。相反,您可以使用puppeteerPoolOptions
选项来控制Chrome(或Chrome)实例,因为代理已绑定到它们(请参见答案1)。
const crawler = new Apify.PuppeteerCrawler({
... // code omitted for brevity
puppeteerPoolOptions: {
maxOpenPagesPerInstance: 1,
retireInstanceAfterRequestCount: 3,
killInstanceAfterSecs: 5,
},
launchPuppeteerFunction: () => {
return Apify.launchPuppeteer({
useApifyProxy: true,
// Use a new proxy with a new IP address for each new Chrome instance
apifyProxySession: Math.random().toString() ,
})
// Or you can use proxyUrl option
// const proxyUrl = Apify.getApifyProxyUrl({ /*groups,*/ session: Math.random().toString() })
// return Apify.launchPuppeteer({
// proxyUrl,
// })
},
...
});
console.log()
。要获取代理的IP,请使用以下代码:...
const request = require('request-promise-native');
...
const session = Math.random().toString();
const proxy = Apify.getApifyProxyUrl({ /*groups,*/ session })
const { clientIp } = await request({ url: 'https://api.apify.com/v2/browser-info', proxy, json: true });
PuppeteerCrawler
时,PuppeteerPool
的基础实例负责创建和处理铬(或铬)实例。那些铬实例是通过Puppeteer在有或没有代理设置的情况下启动的(取决于传递给PuppeteerCrawler
的选项)。