Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
chore: try to change order of puppeteer proxy tests
Martin Adámek0e4e4ea0ffbd
diff --git a/test/crawlers/puppeteer_crawler.test.js b/test/crawlers/puppeteer_crawler.test.jsindex 3131d4abb..2371ea1f0 100644--- a/test/crawlers/puppeteer_crawler.test.js+++ b/test/crawlers/puppeteer_crawler.test.js@@ -360,6 +360,50 @@ describe('PuppeteerCrawler', () => {expect(pageCookies).toEqual(sessionCookies);});+ test('proxy rotation', async () => {+ const used = new Map();+ const puppeteerCrawler = new Apify.PuppeteerCrawler({+ requestList: await Apify.openRequestList(null, [+ { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '1' },+ { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '2' },+ { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '3' },+ { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '4' },+ { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '5' },+ ]),+ launchContext: {+ launchOptions: {+ headless: true,+ },+ // useIncognitoPages: true,+ },+ maxConcurrency: 1,+ sessionPoolOptions: {+ sessionOptions: {+ maxUsageCount: 1,+ },+ },+ proxyConfiguration: await Apify.createProxyConfiguration(),+ async handlePageFunction(context) {+ const { request, page } = context;++ // eslint-disable-next-line no-undef+ const pageContent = await page.$eval('body', (el) => JSON.parse(el.textContent));+ const { clientIp } = pageContent;++ if (used.has(clientIp)) throw new Error(`The ip address ${clientIp} was already used. Proxy rotation does not work properly.`)+ used.set(clientIp, request.url);++ return {+ url: request.url,+ clientIp,+ };+ },+ });++ await puppeteerCrawler.run();+ expect(used.size).toBe(5);+ });+test('proxy per page', async () => {const proxyConfiguration = new ProxyConfiguration({proxyUrls: [@@ -423,48 +467,4 @@ describe('PuppeteerCrawler', () => {expect(count[4]).toBeGreaterThan(0);expect(count[2] + count[3] + count[4]).toBe(6);});-- test('proxy rotation', async () => {- const used = new Map();- const puppeteerCrawler = new Apify.PuppeteerCrawler({- requestList: await Apify.openRequestList(null, [- { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '1' },- { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '2' },- { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '3' },- { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '4' },- { url: 'https://api.apify.com/v2/browser-info', uniqueKey: '5' },- ]),- launchContext: {- launchOptions: {- headless: true,- },- // useIncognitoPages: true,- },- maxConcurrency: 1,- sessionPoolOptions: {- sessionOptions: {- maxUsageCount: 1,- },- },- proxyConfiguration: await Apify.createProxyConfiguration(),- async handlePageFunction(context) {- const { request, page } = context;-- // eslint-disable-next-line no-undef- const pageContent = await page.$eval('body', (el) => JSON.parse(el.textContent));- const { clientIp } = pageContent;-- if (used.has(clientIp)) throw new Error(`The ip address ${clientIp} was already used. Proxy rotation does not work properly.`)- used.set(clientIp, request.url);-- return {- url: request.url,- clientIp,- };- },- });-- await puppeteerCrawler.run();- expect(used.size).toBe(5);- });});