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.

Build docs

Ondra Urban987b8dc37855
diff --git a/docs/api/CheerioCrawler.md b/docs/api/CheerioCrawler.md
index 38bc3e200..9bbfb52d3 100644
--- a/docs/api/CheerioCrawler.md
+++ b/docs/api/CheerioCrawler.md
@@ -137,7 +137,7 @@ await crawler.run();
- `strictSSL`: use `options.ignoreSslErrors`
- `proxy`: use `options.useApifyProxy` or `options.proxyUrls`
</code></pre></td></tr><tr>
-<td><code>[options.handlePageTimeoutSecs]</code></td><td><code>Number</code></td><td><code>300</code></td>
+<td><code>[options.handlePageTimeoutSecs]</code></td><td><code>Number</code></td><td><code>60</code></td>
</tr>
<tr>
<td colspan="3"><p>Timeout in which the function passed as <code>options.handlePageFunction</code> needs to finish, given in seconds.</p>
@@ -145,7 +145,7 @@ await crawler.run();
<td><code>[options.requestTimeoutSecs]</code></td><td><code>Number</code></td><td><code>30</code></td>
</tr>
<tr>
-<td colspan="3"><p>Timeout in which the function passed as <code>options.requestFunction</code> needs to finish, given in seconds.</p>
+<td colspan="3"><p>Timeout in which the HTTP request to the resource needs to finish, given in seconds.</p>
</td></tr><tr>
<td><code>[options.ignoreSslErrors]</code></td><td><code>Boolean</code></td><td><code>false</code></td>
</tr>
diff --git a/docs/api/KeyValueStore.md b/docs/api/KeyValueStore.md
index f9b7a8f46..f62c29ee1 100644
--- a/docs/api/KeyValueStore.md
+++ b/docs/api/KeyValueStore.md
@@ -67,6 +67,7 @@ await store.delete('some-key');
* [`.getValue(key)`](#KeyValueStore+getValue) ⇒ <code>Promise&lt;(Object|String|Buffer)&gt;</code>
* [`.setValue(key, value, [options])`](#KeyValueStore+setValue) ⇒ <code>Promise</code>
* [`.delete()`](#KeyValueStore+delete) ⇒ <code>Promise</code>
+ * [`.getPublicUrl(key)`](#KeyValueStore+getPublicUrl) ⇒ <code>string</code>
* [`.forEachKey(iteratee, [options])`](#KeyValueStore+forEachKey) ⇒ <code>Promise</code>
<a name="KeyValueStore+getValue"></a>
@@ -188,11 +189,30 @@ otherwise the actor process might finish before the value is stored!
Removes the key-value store either from the Apify cloud storage or from the local directory,
depending on the mode of operation.
+<a name="KeyValueStore+getPublicUrl"></a>
+
+## `keyValueStore.getPublicUrl(key)` ⇒ <code>string</code>
+Returns a URL for the given key that may be used to publicly
+access the value in the remote key value store.
+
+<table>
+<thead>
+<tr>
+<th>Param</th><th>Type</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td><code>key</code></td><td><code>string</code></td>
+</tr>
+<tr>
+</tr></tbody>
+</table>
<a name="KeyValueStore+forEachKey"></a>
## `keyValueStore.forEachKey(iteratee, [options])` ⇒ <code>Promise</code>
Iterates over key value store keys, yielding each in turn to an `iteratee` function.
-Each invocation of `iteratee` is called with two arguments: `(item, index)`.
+Each invocation of `iteratee` is called with three arguments: `(item, index, info)`.
If the `iteratee` function returns a Promise then it is awaited before the next call.
If it throws an error, the iteration is aborted and the `forEachKey` function throws the error.
@@ -200,8 +220,8 @@ If it throws an error, the iteration is aborted and the `forEachKey` function th
**Example usage**
```javascript
const keyValueStore = await Apify.openKeyValueStore();
-keyValueStore.forEachKey(async (key, index) => {
- console.log(`Key at ${index}: ${key}`);
+keyValueStore.forEachKey(async (key, index, info) => {
+ console.log(`Key at ${index}: ${key} has size ${info.size}`);
});
```
diff --git a/docs/api/PseudoUrl.md b/docs/api/PseudoUrl.md
index eeea316a6..245fa50a6 100644
--- a/docs/api/PseudoUrl.md
+++ b/docs/api/PseudoUrl.md
@@ -4,7 +4,7 @@ title: PseudoUrl
---
<a name="PseudoUrl"></a>
-Represents a pseudo URL (PURL) - an URL pattern used by web crawlers
+Represents a pseudo-URL (PURL) - an URL pattern used by web crawlers
to specify which URLs should the crawler visit.
This class is used by the [`utils.enqueueLinks()`](utils#utils.enqueueLinks) function.
@@ -12,7 +12,10 @@ A PURL is simply a URL with special directives enclosed in `[]` brackets.
Currently, the only supported directive is `[RegExp]`,
which defines a JavaScript-style regular expression to match against the URL.
-The matching of PURLs against URLs is always case insensitive.
+The `PseudoUrl` class can be constructed either using a pseudo-URL string
+or a regular expression (an instance of the `RegExp` object).
+With a pseudo-URL string, the matching is always case-insensitive.
+If you need case-sensitive matching, use an appropriate `RegExp` object.
For example, a PURL `http://www.example.com/pages/[(\w|-)*]` will match all of the following URLs:
@@ -22,6 +25,7 @@ For example, a PURL `http://www.example.com/pages/[(\w|-)*]` will match all of t
<li><code>http://www.example.com/pages/something</code></li>
</ul>
+Be careful to correctly escape special characters in the pseudo-URL string.
If either `[` or `]` is part of the normal query string, it must be encoded as `[\x5B]` or `[\x5D]`,
respectively. For example, the following PURL:
```http
@@ -32,13 +36,20 @@ will match the URL:
http://www.example.com/search?do[load]=1
```
+If the regular expression in the pseudo-URL contains a backslash character (\),
+you need to escape it with another back backslash, as shown in the example below.
+
**Example usage:**
```javascript
-const purl = new Apify.PseudoUrl('http://www.example.com/pages/[(\w|-)*]', {
+// Using a pseudo-URL string
+const purl = new Apify.PseudoUrl('http://www.example.com/pages/[(\\w|-)+]', {
userData: { foo: 'bar' },
});
+// Using a regular expression
+const purl2 = new Apify.PseudoUrl(/http:\/\/www\.example\.com\/pages\/(\w|-)+/);
+
if (purl.matches('http://www.example.com/pages/my-awesome-page')) console.log('Match!');
```
@@ -62,7 +73,9 @@ if (purl.matches('http://www.example.com/pages/my-awesome-page')) console.log('M
<td><code>purl</code></td><td><code>String</code> | <code>RegExp</code></td>
</tr>
<tr>
-<td colspan="3"><p>Pseudo URL string or a RegExp instance.</p>
+<td colspan="3"><p>A pseudo-URL string or a regular expression object.
+ Using a <code>RegExp</code> instance enables more granular control,
+ such as making the matching case sensitive.</p>
</td></tr><tr>
<td><code>requestTemplate</code></td><td><code>Object</code></td>
</tr>
@@ -76,7 +89,7 @@ if (purl.matches('http://www.example.com/pages/my-awesome-page')) console.log('M
## `pseudoUrl.matches(url)` ⇒ <code>Boolean</code>
Determines whether a URL matches this pseudo-URL pattern.
-**Returns**: <code>Boolean</code> - Returns `true` if given URL matches pseudo URL.
+**Returns**: <code>Boolean</code> - Returns `true` if given URL matches pseudo-URL.
<table>
<thead>
<tr>
diff --git a/docs/api/PuppeteerCrawler.md b/docs/api/PuppeteerCrawler.md
index a46437107..5b67becd2 100644
--- a/docs/api/PuppeteerCrawler.md
+++ b/docs/api/PuppeteerCrawler.md
@@ -121,7 +121,7 @@ await crawler.run();
<td colspan="3"><p>Dynamic queue of URLs to be processed. This is useful for recursive crawling of websites.
Either <code>requestList</code> or <code>requestQueue</code> option must be provided (or both).</p>
</td></tr><tr>
-<td><code>[options.handlePageTimeoutSecs]</code></td><td><code>Number</code></td><td><code>300</code></td>
+<td><code>[options.handlePageTimeoutSecs]</code></td><td><code>Number</code></td><td><code>60</code></td>
</tr>
<tr>
<td colspan="3"><p>Timeout in which the function passed as <code>options.handlePageFunction</code> needs to finish, in seconds.</p>
diff --git a/docs/api/Request.md b/docs/api/Request.md
index 740799d28..fbe29475f 100644
--- a/docs/api/Request.md
+++ b/docs/api/Request.md
@@ -49,6 +49,15 @@ const foo = request.userData.foo;
<tr>
<td colspan="3"><p>URL of the web page to crawl.</p>
</td></tr><tr>
+<td><code>loadedUrl</code></td><td><code>String</code></td>
+</tr>
+<tr>
+<td colspan="3"><p>An actually loaded URL after redirects, if present. HTTP redirects are guaranteed
+ to be included.</p>
+<p> When using <a href="puppeteercrawler"><code>PuppeteerCrawler</code></a>, meta tag and JavaScript redirects may,
+ or may not be included, depending on their nature. This generally means that redirects,
+ which happen immediately will most likely be included, but delayed redirects will not.</p>
+</td></tr><tr>
<td><code>uniqueKey</code></td><td><code>String</code></td>
</tr>
<tr>
diff --git a/docs/api/RequestList.md b/docs/api/RequestList.md
index 303c8b01c..826a77261 100644
--- a/docs/api/RequestList.md
+++ b/docs/api/RequestList.md
@@ -115,11 +115,18 @@ await requestList.reclaimRequest(request2);
<td><code>[options.persistStateKey]</code></td><td><code>String</code></td><td></td>
</tr>
<tr>
-<td colspan="3"><p>Identifies the keys in the default key-value store under which the <code>RequestList</code> persists its
- initial sources and current state. State represents a position of the last scraped request in the list.
- If this is set then <code>RequestList</code>persists all of its sources and the state in regular intervals
+<td colspan="3"><p>Identifies the key in the default key-value store under which the <code>RequestList</code> persists its
+ current state. State represents a position of the last scraped request in the list.
+ If this is set then <code>RequestList</code>persists the state in regular intervals
to key value store and loads the state from there in case it is restarted due to an error or system reboot.</p>
</td></tr><tr>
+<td><code>[options.persistSourcesKey]</code></td><td><code>String</code></td><td></td>
+</tr>
+<tr>
+<td colspan="3"><p>Identifies the key in the default key-value store under which the <code>RequestList</code> persists its
+ initial sources. If this is set then <code>RequestList</code>persists all of its sources
+ to key value store at initialization and loads them from there in case it is restarted due to an error or system reboot.</p>
+</td></tr><tr>
<td><code>[options.state]</code></td><td><code>Object</code></td><td></td>
</tr>
<tr>
diff --git a/docs/api/RequestQueue.md b/docs/api/RequestQueue.md
index 9af889de4..096044e76 100644
--- a/docs/api/RequestQueue.md
+++ b/docs/api/RequestQueue.md
@@ -156,8 +156,9 @@ Marks request handled after successful processing.
<a name="RequestQueue+reclaimRequest"></a>
## `requestQueue.reclaimRequest(request, [options])` ⇒ [<code>Promise&lt;QueueOperationInfo&gt;</code>](../typedefs/queueoperationinfo)
-Reclaims failed request back to the queue,
-so that it can be processed later again.
+Reclaims failed request back to the queue, so that it can be processed later again.
+The request record in the queue is updated using the provided `request` parameter.
+For example, this lets you store the number of retries for the request.
<table>
<thead>