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.

Update changelog, bump version, build

Ondra Urbanefb1347b4478
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a044a31a1..7a4036af3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,9 +1,17 @@
-NEXT
+0.20.0 /
====================
+- **BREAKING:** `Apify.utils.requestAsBrowser()` no longer aborts request on status code 406
+ or when other than `text/html` type is received. Use `options.abortFunction` if you want to
+ retain this functionality.
+- **BREAKING:** Added `useLenientHttpParser` option to `Apify.utils.requestAsBrowser()` which
+ is `true` by default and forces the function to use a HTTP parser that is less strict than
+ default Node 12 parser, but also less secure. It is needed to be able to bypass certain
+ anti-scraping walls and fetch websites that do not comply with HTTP spec.
- Improved `Apify.launchPuppeteer()` code to prevent triggering bugs in Puppeteer by passing
more than required options to `puppeteer.launch()`.
- Documented `BasicCrawler.autoscaledPool` property,
- and added `CheerioCrawler.autoscaledPool` and `PuppeteerCrawler.autoscaledPool` properties
+ and added `CheerioCrawler.autoscaledPool` and `PuppeteerCrawler.autoscaledPool` properties.
+- Added TypeScript typings and typedef documentation for all entities used throughout SDK.
0.19.1 / 2020-01-30
====================
diff --git a/docs/api/utils.md b/docs/api/utils.md
index ce06e63f7..01236cdab 100644
--- a/docs/api/utils.md
+++ b/docs/api/utils.md
@@ -139,7 +139,11 @@ objects.
## `utils.requestAsBrowser` ⇒ `Promise<(http.IncomingMessage|stream.Readable)>`
-Sends a HTTP request that looks like a request sent by a web browser, fully emulating browser's HTTP headers.
+**IMPORTANT WARNING:** This function uses an insecure version of HTTP parser by default and also ignores SSL/TLS errors. This is very useful in
+scraping, because it allows bypassing certain anti-scraping walls, but it also makes it vulnerable to attacks. Do not use this function in other than
+scraping scenarios, unless you set `useLenientHttpParser: false` and `ignoreSslErrors: false`.
+
+Sends an HTTP request that looks like a request sent by a web browser, fully emulating browser's HTTP headers.
This function is useful for web scraping of websites that send the full HTML in the first response. Thanks to this function, the target web server has
no simple way to find out the request hasn't been sent by a full web browser. Using a headless browser for such requests is an order of magnitude more
diff --git a/docs/typedefs/RequestAsBrowserOptions.md b/docs/typedefs/RequestAsBrowserOptions.md
index eb249229a..6333b3047 100644
--- a/docs/typedefs/RequestAsBrowserOptions.md
+++ b/docs/typedefs/RequestAsBrowserOptions.md
@@ -47,7 +47,7 @@ title: RequestAsBrowserOptions
<tr>
<td colspan="3"><p>Two-letter ISO 3166 country code.</p>
</td></tr><tr>
-<td><code>[isMobile]</code></td><td><code>Boolean</code></td><td></td>
+<td><code>[useMobileVersion]</code></td><td><code>Boolean</code></td><td></td>
</tr>
<tr>
<td colspan="3"><p>If <code>true</code>, the function uses User-Agent of a mobile browser.</p>
@@ -58,5 +58,19 @@ title: RequestAsBrowserOptions
<td colspan="3"><p>Function accepts <code>response</code> object as a single parameter and should return true or false.
If function returns true request gets aborted. This function is passed to the
(@apify/http-request)[<a href="https://www.npmjs.com/package/@apify/http-request%5D">https://www.npmjs.com/package/@apify/http-request]</a> NPM package.</p>
+</td></tr><tr>
+<td><code>[ignoreSslErrors]</code></td><td><code>boolean</code></td><td><code>true</code></td>
+</tr>
+<tr>
+<td colspan="3"><p>If set to true, SSL/TLS certificate errors will be ignored.</p>
+</td></tr><tr>
+<td><code>[useLenientHttpParser]</code></td><td><code>boolean</code></td><td><code>true</code></td>
+</tr>
+<tr>
+<td colspan="3"><p>Node.js HTTP parser is stricter than Browser parsers. This prevents fetching of some websites
+ whose servers do not comply with HTTP specs or employ anti-scraping protections due to
+ various parse errors, typically <code>invalid header value char</code> error. This option forces
+ the parser to ignore certain errors and allow those websites to be scraped.
+ However, it will also open your application to various security vulnerabilities.</p>
</td></tr></tbody>
</table>
diff --git a/package.json b/package.json
index d7dbea93a..0ffc2a400 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "apify",
- "version": "0.19.2",
+ "version": "0.20.0",
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
"engines": {
"node": ">=10.17.0"
diff --git a/types/crawlers/cheerio_crawler.d.ts b/types/crawlers/cheerio_crawler.d.ts
index 591814408..e864367bc 100644
--- a/types/crawlers/cheerio_crawler.d.ts
+++ b/types/crawlers/cheerio_crawler.d.ts
@@ -519,28 +519,28 @@ declare class CheerioCrawler {
*/
constructor(options?: CheerioCrawlerOptions);
supportedMimeTypes: Set<string>;
- requestOptions: any;
- handlePageFunction: any;
+ requestOptions: utilsRequest.RequestAsBrowserOptions;
+ handlePageFunction: CheerioHandlePage;
handlePageTimeoutMillis: number;
requestTimeoutMillis: number;
- ignoreSslErrors: any;
- useApifyProxy: any;
- apifyProxyGroups: any;
- apifyProxySession: any;
+ ignoreSslErrors: boolean;
+ useApifyProxy: boolean;
+ apifyProxyGroups: string[];
+ apifyProxySession: string;
proxyUrls: any;
lastUsedProxyUrlIndex: number;
- prepareRequestFunction: any;
- persistCookiesPerSession: any;
- useSessionPool: any;
- basicCrawler: BasicCrawler;
- isRunningPromise: Promise<void>;
+ prepareRequestFunction: PrepareRequest;
+ persistCookiesPerSession: boolean;
+ useSessionPool: boolean;
+ basicCrawler: any;
+ isRunningPromise: any;
/**
* Runs the crawler. Returns promise that gets resolved once all the requests got processed.
*
* @return {Promise}
*/
run(): Promise<any>;
- autoscaledPool: AutoscaledPool;
+ autoscaledPool: any;
/**
* Wrapper around handlePageFunction that opens and closes pages etc.
*
@@ -554,7 +554,7 @@ declare class CheerioCrawler {
request: Request;
autoscaledPool: AutoscaledPool;
session: Session;
- }): Promise<any>;
+ }): Promise<void>;
/**
* Function to make the HTTP request. It performs optimizations
* on the request such as only downloading the request body if the
@@ -593,7 +593,17 @@ declare class CheerioCrawler {
* @param {Session?} session
* @ignore
*/
- _getRequestOptions(request: Request, session: Session): any;
+ _getRequestOptions(request: Request, session: Session): utilsRequest.RequestAsBrowserOptions & {
+ url: any;
+ method: any;
+ headers: any;
+ ignoreSslErrors: boolean;
+ proxyUrl: string;
+ stream: boolean;
+ useCaseSensitiveHeaders: boolean;
+ abortFunction: (res: any) => boolean;
+ timeoutSecs: number;
+ };
/**
* Enables the use of a proxy by returning a proxy URL
* based on configured options or null if no proxy is used.
@@ -626,6 +636,17 @@ declare class CheerioCrawler {
* @private
*/
_handleRequestTimeout(session: Session): void;
+ /**
+ * @param {Object} options
+ * @param {Error} options.error
+ * @param {Request} options.request
+ * @return {Promise<void>}
+ * @ignore
+ */
+ _defaultHandleFailedRequestFunction({ error, request }: {
+ error: Error;
+ request: Request;
+ }): Promise<void>;
}
import { RequestList } from "../request_list";
import { RequestQueue } from "../request_queue";
@@ -636,5 +657,4 @@ import { SessionPoolOptions } from "../session_pool/session_pool";
import Request from "../request";
import { IncomingMessage } from "http";
import AutoscaledPool from "../autoscaling/autoscaled_pool";
-import BasicCrawler from "./basic_crawler";
import { Session } from "../session_pool/session";
diff --git a/types/crawlers/puppeteer_crawler.d.ts b/types/crawlers/puppeteer_crawler.d.ts
index 2205eb4c6..cefaafd7e 100644
--- a/types/crawlers/puppeteer_crawler.d.ts
+++ b/types/crawlers/puppeteer_crawler.d.ts
@@ -488,11 +488,13 @@ declare class PuppeteerCrawler {
}): Promise<PuppeteerResponse>;
/**
* @param {Object} options
+ * @param {Error} options.error
* @param {Request} options.request
* @return {Promise<void>}
* @ignore
*/
- _defaultHandleFailedRequestFunction({ request }: {
+ _defaultHandleFailedRequestFunction({ error, request }: {
+ error: Error;
request: Request;
}): Promise<void>;
}
diff --git a/types/utils_request.d.ts b/types/utils_request.d.ts
index db35acab0..f23231525 100644
--- a/types/utils_request.d.ts
+++ b/types/utils_request.d.ts
@@ -1,19 +1,5 @@
export const FIREFOX_MOBILE_USER_AGENT: "Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0";
export const FIREFOX_DESKTOP_USER_AGENT: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0";
-export namespace REQUEST_AS_BROWSER_DEFAULT_OPTIONS {
- export const countryCode: string;
- export const languageCode: string;
- export const headers: {};
- export const method: string;
- export const useMobileVersion: boolean;
- export const useBrotli: boolean;
- export const json: boolean;
- export function abortFunction(res: any): boolean;
- export const useCaseSensitiveHeaders: boolean;
- export const useStream: boolean;
- export const proxyUrl: any;
- export const timeoutSecs: number;
-}
export function requestAsBrowser(options: RequestAsBrowserOptions): Promise<any>;
/**
* (@apify/http-request)[https://www.npmjs.com/package/@apify/http-request] NPM package.
@@ -48,7 +34,7 @@ export type RequestAsBrowserOptions = {
/**
* If `true`, the function uses User-Agent of a mobile browser.
*/
- isMobile?: boolean;
+ useMobileVersion?: boolean;
/**
* Function accepts `response` object as a single parameter and should return true or false.
* If function returns true request gets aborted. This function is passed to the