Skip to content

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.

Fix CheerioCrawler proxy bug

Ondra Urban6510a8b9d937
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 380537148..2c8c75e88 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+0.8.18 / 2018-10-30
+===================
+- Fix a bug in `CheerioCrawler` where `useApifyProxy` would only work with `apifyProxyGroups`.
+
0.8.17 / 2018-10-30
===================
- Reworked `request.pushErrorMessage()` to support any message and not throw.
diff --git a/package.json b/package.json
index 5080b921d..a343a92cd 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "apify",
- "version": "0.8.17",
+ "version": "0.8.18",
"description": "The scalable web crawling and scraping library for JavaScript",
"engines": {
"node": ">=8.0.0"
diff --git a/src/cheerio_crawler.js b/src/cheerio_crawler.js
index f60d3daa4..604f8f130 100644
--- a/src/cheerio_crawler.js
+++ b/src/cheerio_crawler.js
@@ -335,7 +335,7 @@ class CheerioCrawler {
_getProxyUrl() {
if (this.useApifyProxy) {
return getApifyProxyUrl({
- groups: [...this.apifyProxyGroups],
+ groups: this.apifyProxyGroups,
session: this.apifyProxySession,
groupsParamName: 'options.apifyProxyGroups',
sessionParamName: 'options.apifyProxySession',
diff --git a/test/cheerio_crawler.js b/test/cheerio_crawler.js
index 7eca2ca1e..6630b3195 100644
--- a/test/cheerio_crawler.js
+++ b/test/cheerio_crawler.js
@@ -307,6 +307,35 @@ describe('CheerioCrawler', () => {
process.env[ENV_VARS.PROXY_PASSWORD] = 'abc123';
const proxies = [];
const useApifyProxy = true;
+
+ const proxy = Apify.getApifyProxyUrl();
+
+ const crawler = new Apify.CheerioCrawler({
+ requestList,
+ handlePageFunction: async () => {},
+ requestFunction: async ({ request }) => {
+ const opts = crawler._getRequestOptions(request);
+ proxies.push(opts.proxy);
+ // it needs to return something valid
+ return 'html';
+ },
+ useApifyProxy,
+ });
+
+ await crawler.run();
+ delete process.env[ENV_VARS.PROXY_PASSWORD];
+
+ // expect(proxies).to.have.lengthOf(1);
+ expect(proxies[0]).to.be.eql(proxy);
+ expect(proxies[1]).to.be.eql(proxy);
+ expect(proxies[2]).to.be.eql(proxy);
+ expect(proxies[3]).to.be.eql(proxy);
+ });
+
+ it('should work with useApifyProxy and other opts', async () => {
+ process.env[ENV_VARS.PROXY_PASSWORD] = 'abc123';
+ const proxies = [];
+ const useApifyProxy = true;
const apifyProxyGroups = ['GROUP1', 'GROUP2'];
const apifyProxySession = 'session';