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
Merge develop
Ondra Urbana6f0e209f715
diff --cc src/cheerio_crawler.jsindex 97c50d6cd,4023453ed..3ff3b8d8b--- a/src/cheerio_crawler.js+++ b/src/cheerio_crawler.js@@@ -422,27 -353,38 +428,60 @@@ class CheerioCrawlerreturn null;}+ /**+ * Flushes the provided stream into a Buffer and transforms+ * it to a String using the provided encoding or utf-8 as default.+ *+ * @param {stream.Readable} stream+ * @param {String} [encoding]+ * @returns {Promise<String>}+ * @private+ */+ async _readStreamIntoString(stream, encoding) { // eslint-disable-line class-methods-use-this+ return new Promise((resolve, reject) => {+ const chunks = [];+ stream+ .on('data', chunk => chunks.push(chunk))+ .on('error', err => reject(err))+ .on('end', () => {+ const buffer = Buffer.concat(chunks);+ resolve(buffer.toString(encoding));+ });+ });+ }+++ /**+ * The handler this function attaches overcomes a long standing bug in+ * the tunnel-agent NPM package that is used by the Request package internally.+ * The package throws an assertion error in a callback scope that cannot be+ * caught by conventional means and shuts down the running process.+ * @ignore+ */+ _suppressTunnelAgentAssertError() {+ // Only set the handler if it's not already set.+ if (this.tunnelAgentExceptionListener) return;+ this.tunnelAgentExceptionListener = process.on('uncaughtException', (err) => {+ try {+ const code = err.code === 'ERR_ASSERTION';+ const name = err.name === 'AssertionError [ERR_ASSERTION]';+ const operator = err.operator === '==';+ const value = err.expected === 0;+ const stack = err.stack.includes('/tunnel-agent/index.js');+ // If this passes, we can be reasonably sure that it's+ // the right error from tunnel-agent.+ if (code && name && operator && value && stack) {+ log.error('CheerioCrawler: Tunnel-Agent assertion error intercepted. The affected request will timeout.');+ return;+ }+ } catch (caughtError) {+ // Catch any exception resulting from the duck-typing+ // check. It only means that the error is not the one+ // we're looking for.+ }+ // Rethrow the original error if it's not a match.+ throw err;+ });+ }}export default CheerioCrawler;