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.

Improve maxRequestPerCrawl log message

Ondra Urbane0b6714b2a1d
diff --git a/src/basic_crawler.js b/src/basic_crawler.js
index bc01710d5..e5a79adf2 100644
--- a/src/basic_crawler.js
+++ b/src/basic_crawler.js
@@ -181,6 +181,7 @@ class BasicCrawler {
this.maxRequestRetries = maxRequestRetries;
this.handledRequestsCount = 0;
+ let shouldLogMaxPagesExceeded = true;
const isMaxPagesExceeded = () => maxRequestsPerCrawl && maxRequestsPerCrawl <= this.handledRequestsCount;
const { isFinishedFunction } = autoscaledPoolOptions;
@@ -190,14 +191,22 @@ class BasicCrawler {
maxConcurrency,
runTaskFunction: this._runTaskFunction.bind(this),
isTaskReadyFunction: async () => {
- if (isMaxPagesExceeded()) return false;
+ if (isMaxPagesExceeded()) {
+ if (shouldLogMaxPagesExceeded) {
+ log.info('BasicCrawler: Crawler reached the maxRequestsPerCrawl limit of '
+ + `${maxRequestsPerCrawl} requests and will shut down soon. Requests that are in progress will be allowed to finish.`);
+ shouldLogMaxPagesExceeded = false;
+ }
+ return false;
+ }
return this._isTaskReadyFunction();
},
isFinishedFunction: async () => {
if (isMaxPagesExceeded()) {
- log.info('BasicCrawler: Crawler reached the max requests per crawl limit by crawling '
- + `${this.handledRequestsCount} requests and will shut down.`);
+ log.info(`BasicCrawler: Earlier, the crawler reached the maxRequestsPerCrawl limit of ${maxRequestsPerCrawl} requests `
+ + 'and all requests that were in progress at that time have now finished. '
+ + `In total, the crawler processed ${this.handledRequestsCount} requests and will shut down.`);
return true;
}