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.

Format documentation with Prettier

David Turnbull277463bf7d66
diff --git a/docs/api/Apify.md b/docs/api/Apify.md
index efcc6eaaa..38d568bf3 100644
--- a/docs/api/Apify.md
+++ b/docs/api/Apify.md
@@ -9,27 +9,27 @@ The following section describes all functions and properties provided by the `ap
except individual classes and namespaces that have their separate, detailed, documentation pages
accessible from the left sidebar.
-- [Apify](#module_Apify)
- - [`.addWebhook(options)`](#module_Apify.addWebhook) ⇒ `Promise<Object>`
- - [`.call(actId, [input], [options])`](#module_Apify.call) ⇒ [`Promise<ActorRun>`](../typedefs/actorrun)
- - [`.callTask(taskId, [input], [options])`](#module_Apify.callTask) ⇒ [`Promise<ActorRun>`](../typedefs/actorrun)
- - [`.client`](#module_Apify.client)
- - [`.events`](#module_Apify.events)
- - [`.getApifyProxyUrl(options)`](#module_Apify.getApifyProxyUrl) ⇒ `String`
- - [`.getEnv()`](#module_Apify.getEnv) ⇒ `Object`
- - [`.getInput`](#module_Apify.getInput) ⇒ `Promise<Object>`
- - [`.getMemoryInfo()`](#module_Apify.getMemoryInfo) ⇒ `Promise<Object>`
- - [`.getValue(key)`](#module_Apify.getValue) ⇒ `Promise<Object>`
- - [`.isAtHome()`](#module_Apify.isAtHome) ⇒ `Boolean`
- - [`.launchPuppeteer([options])`](#module_Apify.launchPuppeteer) ⇒ `Promise<Browser>`
- - [`.main(userFunc)`](#module_Apify.main)
- - [`.metamorph(targetActorId, [input], [options])`](#module_Apify.metamorph) ⇒ `Promise`
- - [`.openDataset([datasetIdOrName], [options])`](#module_Apify.openDataset) ⇒ [`Promise<Dataset>`](dataset)
- - [`.openKeyValueStore([storeIdOrName], [options])`](#module_Apify.openKeyValueStore) ⇒ [`Promise<KeyValueStore>`](keyvaluestore)
- - [`.openRequestList`](#module_Apify.openRequestList) ⇒ [`Promise<RequestList>`](requestlist)
- - [`.openRequestQueue`](#module_Apify.openRequestQueue) ⇒ [`Promise<RequestQueue>`](requestqueue)
- - [`.pushData(item)`](#module_Apify.pushData) ⇒ `Promise`
- - [`.setValue(key, value, [options])`](#module_Apify.setValue) ⇒ `Promise`
+- [Apify](#module_Apify)
+ - [`.addWebhook(options)`](#module_Apify.addWebhook) ⇒ `Promise<Object>`
+ - [`.call(actId, [input], [options])`](#module_Apify.call) ⇒ [`Promise<ActorRun>`](../typedefs/actorrun)
+ - [`.callTask(taskId, [input], [options])`](#module_Apify.callTask) ⇒ [`Promise<ActorRun>`](../typedefs/actorrun)
+ - [`.client`](#module_Apify.client)
+ - [`.events`](#module_Apify.events)
+ - [`.getApifyProxyUrl(options)`](#module_Apify.getApifyProxyUrl) ⇒ `String`
+ - [`.getEnv()`](#module_Apify.getEnv) ⇒ `Object`
+ - [`.getInput`](#module_Apify.getInput) ⇒ `Promise<Object>`
+ - [`.getMemoryInfo()`](#module_Apify.getMemoryInfo) ⇒ `Promise<Object>`
+ - [`.getValue(key)`](#module_Apify.getValue) ⇒ `Promise<Object>`
+ - [`.isAtHome()`](#module_Apify.isAtHome) ⇒ `Boolean`
+ - [`.launchPuppeteer([options])`](#module_Apify.launchPuppeteer) ⇒ `Promise<Browser>`
+ - [`.main(userFunc)`](#module_Apify.main)
+ - [`.metamorph(targetActorId, [input], [options])`](#module_Apify.metamorph) ⇒ `Promise`
+ - [`.openDataset([datasetIdOrName], [options])`](#module_Apify.openDataset) ⇒ [`Promise<Dataset>`](dataset)
+ - [`.openKeyValueStore([storeIdOrName], [options])`](#module_Apify.openKeyValueStore) ⇒ [`Promise<KeyValueStore>`](keyvaluestore)
+ - [`.openRequestList`](#module_Apify.openRequestList) ⇒ [`Promise<RequestList>`](requestlist)
+ - [`.openRequestQueue`](#module_Apify.openRequestQueue) ⇒ [`Promise<RequestQueue>`](requestqueue)
+ - [`.pushData(item)`](#module_Apify.pushData) ⇒ `Promise`
+ - [`.setValue(key, value, [options])`](#module_Apify.setValue) ⇒ `Promise`
<a name="module_Apify.addWebhook"></a>
@@ -119,7 +119,7 @@ and several other API endpoints to obtain the output.
**Throws**:
-- [`ApifyCallError`](../typedefs/apifycallerror) If the run did not succeed, e.g. if it failed or timed out.
+- [`ApifyCallError`](../typedefs/apifycallerror) If the run did not succeed, e.g. if it failed or timed out.
<table>
<thead>
@@ -230,7 +230,7 @@ and several other API endpoints to obtain the output.
**Throws**:
-- [`ApifyCallError`](../typedefs/apifycallerror) If the run did not succeed, e.g. if it failed or timed out.
+- [`ApifyCallError`](../typedefs/apifycallerror) If the run did not succeed, e.g. if it failed or timed out.
<table>
<thead>
@@ -328,7 +328,7 @@ The event emitter is initialized by calling the [`Apify.main()`](#module_Apify.m
```javascript
Apify.events.on("cpuInfo", data => {
- if (data.isCpuOverloaded) console.log("Oh no, the CPU is overloaded!");
+ if (data.isCpuOverloaded) console.log("Oh no, the CPU is overloaded!");
});
```
@@ -673,8 +673,8 @@ The user function can be synchronous:
```javascript
Apify.main(() => {
- // My synchronous function that returns immediately
- console.log("Hello world from actor!");
+ // My synchronous function that returns immediately
+ console.log("Hello world from actor!");
});
```
@@ -684,10 +684,10 @@ If the user function returns a promise, it is considered asynchronous:
const request = require("request-promise-native");
Apify.main(() => {
- // My asynchronous function that returns a promise
- return request("http://www.example.com").then(html => {
- console.log(html);
- });
+ // My asynchronous function that returns a promise
+ return request("http://www.example.com").then(html => {
+ console.log(html);
+ });
});
```
@@ -697,9 +697,9 @@ To simplify your code, you can take advantage of the `async`/`await` keywords:
const request = require("request-promise-native");
Apify.main(async () => {
- // My asynchronous function
- const html = await request("http://www.example.com");
- console.log(html);
+ // My asynchronous function
+ const html = await request("http://www.example.com");
+ console.log(html);
});
```
@@ -857,9 +857,9 @@ For more details and code examples, see the [`RequestList`](requestlist) class.
```javascript
const sources = [
- "https://www.example.com",
- "https://www.google.com",
- "https://www.bing.com"
+ "https://www.example.com",
+ "https://www.google.com",
+ "https://www.bing.com"
];
const requestList = await Apify.openRequestList("my-name", sources);
diff --git a/docs/api/AutoscaledPool.md b/docs/api/AutoscaledPool.md
index 151979f80..e8874aec2 100644
--- a/docs/api/AutoscaledPool.md
+++ b/docs/api/AutoscaledPool.md
@@ -33,37 +33,37 @@ and also in the interval set by the `options.maybeRunIntervalSecs` parameter.
```javascript
const pool = new Apify.AutoscaledPool({
- maxConcurrency: 50,
- runTaskFunction: async () => {
- // Run some resource-intensive asynchronous operation here.
- },
- isTaskReadyFunction: async () => {
- // Tell the pool whether more tasks are ready to be processed.
- // Return true or false
- },
- isFinishedFunction: async () => {
- // Tell the pool whether it should finish
- // or wait for more tasks to become available.
- // Return true or false
- }
+ maxConcurrency: 50,
+ runTaskFunction: async () => {
+ // Run some resource-intensive asynchronous operation here.
+ },
+ isTaskReadyFunction: async () => {
+ // Tell the pool whether more tasks are ready to be processed.
+ // Return true or false
+ },
+ isFinishedFunction: async () => {
+ // Tell the pool whether it should finish
+ // or wait for more tasks to become available.
+ // Return true or false
+ }
});
await pool.run();
```
-- [AutoscaledPool](autoscaledpool)
- - [`new AutoscaledPool(options)`](#new_AutoscaledPool_new)
- - [`.minConcurrency`](#AutoscaledPool+minConcurrency) ⇒ `number`
- - [`.minConcurrency`](#AutoscaledPool+minConcurrency)
- - [`.maxConcurrency`](#AutoscaledPool+maxConcurrency) ⇒ `number`
- - [`.maxConcurrency`](#AutoscaledPool+maxConcurrency)
- - [`.desiredConcurrency`](#AutoscaledPool+desiredConcurrency) ⇒ `number`
- - [`.desiredConcurrency`](#AutoscaledPool+desiredConcurrency)
- - [`.currentConcurrency`](#AutoscaledPool+currentConcurrency) ⇒ `number`
- - [`.run()`](#AutoscaledPool+run) ⇒ `Promise`
- - [`.abort()`](#AutoscaledPool+abort) ⇒ `Promise`
- - [`.pause([timeoutSecs])`](#AutoscaledPool+pause) ⇒ `Promise`
- - [`.resume()`](#AutoscaledPool+resume)
+- [AutoscaledPool](autoscaledpool)
+ - [`new AutoscaledPool(options)`](#new_AutoscaledPool_new)
+ - [`.minConcurrency`](#AutoscaledPool+minConcurrency) ⇒ `number`
+ - [`.minConcurrency`](#AutoscaledPool+minConcurrency)
+ - [`.maxConcurrency`](#AutoscaledPool+maxConcurrency) ⇒ `number`
+ - [`.maxConcurrency`](#AutoscaledPool+maxConcurrency)
+ - [`.desiredConcurrency`](#AutoscaledPool+desiredConcurrency) ⇒ `number`
+ - [`.desiredConcurrency`](#AutoscaledPool+desiredConcurrency)
+ - [`.currentConcurrency`](#AutoscaledPool+currentConcurrency) ⇒ `number`
+ - [`.run()`](#AutoscaledPool+run) ⇒ `Promise`
+ - [`.abort()`](#AutoscaledPool+abort) ⇒ `Promise`
+ - [`.pause([timeoutSecs])`](#AutoscaledPool+pause) ⇒ `Promise`
+ - [`.resume()`](#AutoscaledPool+resume)
<a name="new_AutoscaledPool_new"></a>
diff --git a/docs/api/BasicCrawler.md b/docs/api/BasicCrawler.md
index 708ea6834..ddfeb6ee5 100644
--- a/docs/api/BasicCrawler.md
+++ b/docs/api/BasicCrawler.md
@@ -39,32 +39,32 @@ const rp = require("request-promise-native");
// Prepare a list of URLs to crawl
const requestList = new Apify.RequestList({
- sources: [
- { url: "http://www.example.com/page-1" },
- { url: "http://www.example.com/page-2" }
- ]
+ sources: [
+ { url: "http://www.example.com/page-1" },
+ { url: "http://www.example.com/page-2" }
+ ]
});
await requestList.initialize();
// Crawl the URLs
const crawler = new Apify.BasicCrawler({
- requestList,
- handleRequestFunction: async ({ request }) => {
- // 'request' contains an instance of the Request class
- // Here we simply fetch the HTML of the page and store it to a dataset
- await Apify.pushData({
- url: request.url,
- html: await rp(request.url)
- });
- }
+ requestList,
+ handleRequestFunction: async ({ request }) => {
+ // 'request' contains an instance of the Request class
+ // Here we simply fetch the HTML of the page and store it to a dataset
+ await Apify.pushData({
+ url: request.url,
+ html: await rp(request.url)
+ });
+ }
});
await crawler.run();
```
-- [BasicCrawler](basiccrawler)
- - [`new BasicCrawler(options)`](#new_BasicCrawler_new)
- - [`.run()`](#BasicCrawler+run) ⇒ `Promise`
+- [BasicCrawler](basiccrawler)
+ - [`new BasicCrawler(options)`](#new_BasicCrawler_new)
+ - [`.run()`](#BasicCrawler+run) ⇒ `Promise`
<a name="new_BasicCrawler_new"></a>
diff --git a/docs/api/CheerioCrawler.md b/docs/api/CheerioCrawler.md
index bc92ea1e2..3a08441bd 100644
--- a/docs/api/CheerioCrawler.md
+++ b/docs/api/CheerioCrawler.md
@@ -45,43 +45,43 @@ parameter of the `CheerioCrawler` constructor. For user convenience, the `minCon
```javascript
// Prepare a list of URLs to crawl
const requestList = new Apify.RequestList({
- sources: [
- { url: "http://www.example.com/page-1" },
- { url: "http://www.example.com/page-2" }
- ]
+ sources: [
+ { url: "http://www.example.com/page-1" },
+ { url: "http://www.example.com/page-2" }
+ ]
});
await requestList.initialize();
// Crawl the URLs
const crawler = new Apify.CheerioCrawler({
- requestList,
- handlePageFunction: async ({ request, response, html, $ }) => {
- const data = [];
+ requestList,
+ handlePageFunction: async ({ request, response, html, $ }) => {
+ const data = [];
- // Do some data extraction from the page with Cheerio.
- $(".some-collection").each((index, el) => {
- data.push({
- title: $(el)
- .find(".some-title")
- .text()
- });
- });
+ // Do some data extraction from the page with Cheerio.
+ $(".some-collection").each((index, el) => {
+ data.push({
+ title: $(el)
+ .find(".some-title")
+ .text()
+ });
+ });
- // Save the data to dataset.
- await Apify.pushData({
- url: request.url,
- html,
- data
- });
- }
+ // Save the data to dataset.
+ await Apify.pushData({
+ url: request.url,
+ html,
+ data
+ });
+ }
});
await crawler.run();
```
-- [CheerioCrawler](cheeriocrawler)
- - [`new CheerioCrawler(options)`](#new_CheerioCrawler_new)
- - [`.run()`](#CheerioCrawler+run) ⇒ `Promise`
+- [CheerioCrawler](cheeriocrawler)
+ - [`new CheerioCrawler(options)`](#new_CheerioCrawler_new)
+ - [`.run()`](#CheerioCrawler+run) ⇒ `Promise`
<a name="new_CheerioCrawler_new"></a>
diff --git a/docs/api/Dataset.md b/docs/api/Dataset.md
index 2e05b2b84..99220f6fc 100644
--- a/docs/api/Dataset.md
+++ b/docs/api/Dataset.md
@@ -50,14 +50,14 @@ await dataset.pushData({ foo: "bar" });
await dataset.pushData([{ foo: "bar2", col2: "val2" }, { col3: 123 }]);
```
-- [Dataset](dataset)
- - [`.pushData(data)`](#Dataset+pushData) ⇒ `Promise`
- - [`.getData([options])`](#Dataset+getData) ⇒ `Promise<Object>`
- - [`.getInfo()`](#Dataset+getInfo) ⇒ `Promise<Object>`
- - [`.forEach(iteratee, [options], [index])`](#Dataset+forEach) ⇒ `Promise`
- - [`.map(iteratee, options)`](#Dataset+map) ⇒ `Promise<Array>`
- - [`.reduce(iteratee, memo, options)`](#Dataset+reduce) ⇒ `Promise<*>`
- - [`.delete()`](#Dataset+delete) ⇒ `Promise`
+- [Dataset](dataset)
+ - [`.pushData(data)`](#Dataset+pushData) ⇒ `Promise`
+ - [`.getData([options])`](#Dataset+getData) ⇒ `Promise<Object>`
+ - [`.getInfo()`](#Dataset+getInfo) ⇒ `Promise<Object>`
+ - [`.forEach(iteratee, [options], [index])`](#Dataset+forEach) ⇒ `Promise`
+ - [`.map(iteratee, options)`](#Dataset+map) ⇒ `Promise<Array>`
+ - [`.reduce(iteratee, memo, options)`](#Dataset+reduce) ⇒ `Promise<*>`
+ - [`.delete()`](#Dataset+delete) ⇒ `Promise`
<a name="Dataset+pushData"></a>
@@ -258,7 +258,7 @@ If it throws an error, the iteration is aborted and the `forEach` function throw
```javascript
const dataset = await Apify.openDataset("my-results");
await dataset.forEach(async (item, index) => {
- console.log(`Item at ${index}: ${JSON.stringify(item)}`);
+ console.log(`Item at ${index}: ${JSON.stringify(item)}`);
});
```
diff --git a/docs/api/KeyValueStore.md b/docs/api/KeyValueStore.md
index 7fa5b84db..8beb4d839 100644
--- a/docs/api/KeyValueStore.md
+++ b/docs/api/KeyValueStore.md
@@ -68,12 +68,12 @@ const value = await store.getValue("some-key");
await store.delete("some-key");
```
-- [KeyValueStore](keyvaluestore)
- - [`.getValue(key)`](#KeyValueStore+getValue) ⇒ `Promise<(Object|String|Buffer)>`
- - [`.setValue(key, value, [options])`](#KeyValueStore+setValue) ⇒ `Promise`
- - [`.delete()`](#KeyValueStore+delete) ⇒ `Promise`
- - [`.getPublicUrl(key)`](#KeyValueStore+getPublicUrl) ⇒ `string`
- - [`.forEachKey(iteratee, [options])`](#KeyValueStore+forEachKey) ⇒ `Promise`
+- [KeyValueStore](keyvaluestore)
+ - [`.getValue(key)`](#KeyValueStore+getValue) ⇒ `Promise<(Object|String|Buffer)>`
+ - [`.setValue(key, value, [options])`](#KeyValueStore+setValue) ⇒ `Promise`
+ - [`.delete()`](#KeyValueStore+delete) ⇒ `Promise`
+ - [`.getPublicUrl(key)`](#KeyValueStore+getPublicUrl) ⇒ `string`
+ - [`.forEachKey(iteratee, [options])`](#KeyValueStore+forEachKey) ⇒ `Promise`
<a name="KeyValueStore+getValue"></a>
@@ -238,7 +238,7 @@ If it throws an error, the iteration is aborted and the `forEachKey` function th
```javascript
const keyValueStore = await Apify.openKeyValueStore();
await keyValueStore.forEachKey(async (key, index, info) => {
- console.log(`Key at ${index}: ${key} has size ${info.size}`);
+ console.log(`Key at ${index}: ${key} has size ${info.size}`);
});
```
diff --git a/docs/api/LiveViewServer.md b/docs/api/LiveViewServer.md
index d531e12e5..d69c4d0b2 100644
--- a/docs/api/LiveViewServer.md
+++ b/docs/api/LiveViewServer.md
@@ -11,10 +11,10 @@ pieces of information, the currently opened URL, the content of the page (HTML)
```json
{
- "pageUrl": "https://www.example.com",
- "htmlContent": "<html><body> ....",
- "screenshotIndex": 3,
- "createdAt": "2019-04-18T11:50:40.060Z"
+ "pageUrl": "https://www.example.com",
+ "htmlContent": "<html><body> ....",
+ "screenshotIndex": 3,
+ "createdAt": "2019-04-18T11:50:40.060Z"
}
```
@@ -36,13 +36,13 @@ single page improves performance and stability dramatically in high concurrency
When running locally, it is often best to use a headful browser for debugging, since it provides
a better view into the browser, including DevTools, but `LiveViewServer` works too.
-- [LiveViewServer](liveviewserver)
- - [`new LiveViewServer([options])`](#new_LiveViewServer_new)
- - [`.start()`](#LiveViewServer+start) ⇒ `Promise`
- - [`.stop()`](#LiveViewServer+stop) ⇒ `Promise`
- - [`.serve(page)`](#LiveViewServer+serve) ⇒ `Promise`
- - [`.isRunning()`](#LiveViewServer+isRunning) ⇒ `boolean`
- - [`.hasClients()`](#LiveViewServer+hasClients) ⇒ `boolean`
+- [LiveViewServer](liveviewserver)
+ - [`new LiveViewServer([options])`](#new_LiveViewServer_new)
+ - [`.start()`](#LiveViewServer+start) ⇒ `Promise`
+ - [`.stop()`](#LiveViewServer+stop) ⇒ `Promise`
+ - [`.serve(page)`](#LiveViewServer+serve) ⇒ `Promise`
+ - [`.isRunning()`](#LiveViewServer+isRunning) ⇒ `boolean`
+ - [`.hasClients()`](#LiveViewServer+hasClients) ⇒ `boolean`
<a name="new_LiveViewServer_new"></a>
diff --git a/docs/api/PseudoUrl.md b/docs/api/PseudoUrl.md
index 7f400ac2e..65ec539a8 100644
--- a/docs/api/PseudoUrl.md
+++ b/docs/api/PseudoUrl.md
@@ -48,20 +48,20 @@ you need to escape it with another back backslash, as shown in the example below
```javascript
// Using a pseudo-URL string
const purl = new Apify.PseudoUrl("http://www.example.com/pages/[(\\w|-)+]", {
- userData: { foo: "bar" }
+ 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!");
+ console.log("Match!");
```
-- [PseudoUrl](pseudourl)
- - [`new PseudoUrl(purl, requestTemplate)`](#new_PseudoUrl_new)
- - [`.matches(url)`](#PseudoUrl+matches) ⇒ `Boolean`
- - [`.createRequest(urlOrProps)`](#PseudoUrl+createRequest) ⇒ [`Request`](request)
+- [PseudoUrl](pseudourl)
+ - [`new PseudoUrl(purl, requestTemplate)`](#new_PseudoUrl_new)
+ - [`.matches(url)`](#PseudoUrl+matches) ⇒ `Boolean`
+ - [`.createRequest(urlOrProps)`](#PseudoUrl+createRequest) ⇒ [`Request`](request)
<a name="new_PseudoUrl_new"></a>
diff --git a/docs/api/PuppeteerCrawler.md b/docs/api/PuppeteerCrawler.md
index 2f8d9c5ed..07206c8b6 100644
--- a/docs/api/PuppeteerCrawler.md
+++ b/docs/api/PuppeteerCrawler.md
@@ -43,33 +43,33 @@ to [`PuppeteerPool`](puppeteerpool) constructor.
```javascript
const crawler = new Apify.PuppeteerCrawler({
- requestList,
- handlePageFunction: async ({ page, request }) => {
- // This function is called to extract data from a single web page
- // 'page' is an instance of Puppeteer.Page with page.goto(request.url) already called
- // 'request' is an instance of Request class with information about the page to load
- await Apify.pushData({
- title: await page.title(),
- url: request.url,
- succeeded: true
- });
- },
- handleFailedRequestFunction: async ({ request }) => {
- // This function is called when the crawling of a request failed too many times
- await Apify.pushData({
- url: request.url,
- succeeded: false,
- errors: request.errorMessages
- });
- }
+ requestList,
+ handlePageFunction: async ({ page, request }) => {
+ // This function is called to extract data from a single web page
+ // 'page' is an instance of Puppeteer.Page with page.goto(request.url) already called
+ // 'request' is an instance of Request class with information about the page to load
+ await Apify.pushData({
+ title: await page.title(),
+ url: request.url,
+ succeeded: true
+ });
+ },
+ handleFailedRequestFunction: async ({ request }) => {
+ // This function is called when the crawling of a request failed too many times
+ await Apify.pushData({
+ url: request.url,
+ succeeded: false,
+ errors: request.errorMessages
+ });
+ }
});
await crawler.run();
```
-- [PuppeteerCrawler](puppeteercrawler)
- - [`new PuppeteerCrawler(options)`](#new_PuppeteerCrawler_new)
- - [`.run()`](#PuppeteerCrawler+run) ⇒ `Promise`
+- [PuppeteerCrawler](puppeteercrawler)
+ - [`new PuppeteerCrawler(options)`](#new_PuppeteerCrawler_new)
+ - [`.run()`](#PuppeteerCrawler+run) ⇒ `Promise`
<a name="new_PuppeteerCrawler_new"></a>
diff --git a/docs/api/PuppeteerPool.md b/docs/api/PuppeteerPool.md
index a97ed2bed..2cfc14998 100644
--- a/docs/api/PuppeteerPool.md
+++ b/docs/api/PuppeteerPool.md
@@ -22,12 +22,12 @@ and the retirement of instances helps mitigate effects of memory leaks in Chrome
```javascript
const puppeteerPool = new PuppeteerPool({
- launchPuppeteerFunction: () => {
- // Use a new proxy with a new IP address for each new Chrome instance
- return Apify.launchPuppeteer({
- apifyProxySession: Math.random()
- });
- }
+ launchPuppeteerFunction: () => {
+ // Use a new proxy with a new IP address for each new Chrome instance
+ return Apify.launchPuppeteer({
+ apifyProxySession: Math.random()
+ });
+ }
});
const page1 = await puppeteerPool.newPage();
@@ -40,13 +40,13 @@ const page3 = await puppeteerPool.newPage();
await puppeteerPool.destroy();
```
-- [PuppeteerPool](puppeteerpool)
- - [`new PuppeteerPool([options])`](#new_PuppeteerPool_new)
- - [`.newPage()`](#PuppeteerPool+newPage) ⇒ `Promise<Page>`
- - [`.destroy()`](#PuppeteerPool+destroy) ⇒ `Promise`
- - [`.retire(browser)`](#PuppeteerPool+retire) ⇒ `Promise`
- - [`.recyclePage(page)`](#PuppeteerPool+recyclePage) ⇒ `Promise`
- - [`.serveLiveViewSnapshot(page)`](#PuppeteerPool+serveLiveViewSnapshot) ⇒ `Promise`
+- [PuppeteerPool](puppeteerpool)
+ - [`new PuppeteerPool([options])`](#new_PuppeteerPool_new)
+ - [`.newPage()`](#PuppeteerPool+newPage) ⇒ `Promise<Page>`
+ - [`.destroy()`](#PuppeteerPool+destroy) ⇒ `Promise`
+ - [`.retire(browser)`](#PuppeteerPool+retire) ⇒ `Promise`
+ - [`.recyclePage(page)`](#PuppeteerPool+recyclePage) ⇒ `Promise`
+ - [`.serveLiveViewSnapshot(page)`](#PuppeteerPool+serveLiveViewSnapshot) ⇒ `Promise`
<a name="new_PuppeteerPool_new"></a>
diff --git a/docs/api/Request.md b/docs/api/Request.md
index 74a900134..8547a8768 100644
--- a/docs/api/Request.md
+++ b/docs/api/Request.md
@@ -109,10 +109,10 @@ const foo = request.userData.foo;
</td></tr></tbody>
</table>
-- [Request](request)
- - [`new Request(options)`](#new_Request_new)
- - [`.pushErrorMessage(errorOrMessage, [options])`](#Request+pushErrorMessage)
- - ~~[`.doNotRetry([message])`](#Request+doNotRetry)~~
+- [Request](request)
+ - [`new Request(options)`](#new_Request_new)
+ - [`.pushErrorMessage(errorOrMessage, [options])`](#Request+pushErrorMessage)
+ - ~~[`.doNotRetry([message])`](#Request+doNotRetry)~~
<a name="new_Request_new"></a>
diff --git a/docs/api/RequestList.md b/docs/api/RequestList.md
index b65aaca77..dff501924 100644
--- a/docs/api/RequestList.md
+++ b/docs/api/RequestList.md
@@ -39,20 +39,20 @@ which will prevent any issues that a live list of URLs might cause.
```javascript
const requestList = new Apify.RequestList({
- sources: [
- // Separate requests
- { url: "http://www.example.com/page-1", method: "GET", headers: {} },
- { url: "http://www.example.com/page-2", userData: { foo: "bar" } },
-
- // Bulk load of URLs from file `http://www.example.com/my-url-list.txt`
- // Note that all URLs must start with http:// or https://
- {
- requestsFromUrl: "http://www.example.com/my-url-list.txt",
- userData: { isFromUrl: true }
- }
- ],
- persistStateKey: "my-state",
- persistSourcesKey: "my-sources"
+ sources: [
+ // Separate requests
+ { url: "http://www.example.com/page-1", method: "GET", headers: {} },
+ { url: "http://www.example.com/page-2", userData: { foo: "bar" } },
+
+ // Bulk load of URLs from file `http://www.example.com/my-url-list.txt`
+ // Note that all URLs must start with http:// or https://
+ {
+ requestsFromUrl: "http://www.example.com/my-url-list.txt",
+ userData: { isFromUrl: true }
+ }
+ ],
+ persistStateKey: "my-state",
+ persistSourcesKey: "my-sources"
});
// This call loads and parses the URLs from the remote file.
@@ -70,18 +70,18 @@ await requestList.markRequestHandled(request1);
await requestList.reclaimRequest(request2);
```
-- [RequestList](requestlist)
- - [`new exports.RequestList(options)`](#new_RequestList_new)
- - [`.initialize()`](#RequestList+initialize) ⇒ `Promise`
- - [`.persistState()`](#RequestList+persistState) ⇒ `Promise`
- - [`.getState()`](#RequestList+getState) ⇒ `Object`
- - [`.isEmpty()`](#RequestList+isEmpty) ⇒ `Promise<Boolean>`
- - [`.isFinished()`](#RequestList+isFinished) ⇒ `Promise<Boolean>`
- - [`.fetchNextRequest()`](#RequestList+fetchNextRequest) ⇒ [`Promise<Request>`](request)
- - [`.markRequestHandled(request)`](#RequestList+markRequestHandled) ⇒ `Promise`
- - [`.reclaimRequest(request)`](#RequestList+reclaimRequest) ⇒ `Promise`
- - [`.length()`](#RequestList+length) ⇒ `Number`
- - [`.handledCount()`](#RequestList+handledCount) ⇒ `Number`
+- [RequestList](requestlist)
+ - [`new exports.RequestList(options)`](#new_RequestList_new)
+ - [`.initialize()`](#RequestList+initialize) ⇒ `Promise`
+ - [`.persistState()`](#RequestList+persistState) ⇒ `Promise`
+ - [`.getState()`](#RequestList+getState) ⇒ `Object`
+ - [`.isEmpty()`](#RequestList+isEmpty) ⇒ `Promise<Boolean>`
+ - [`.isFinished()`](#RequestList+isFinished) ⇒ `Promise<Boolean>`
+ - [`.fetchNextRequest()`](#RequestList+fetchNextRequest) ⇒ [`Promise<Request>`](request)
+ - [`.markRequestHandled(request)`](#RequestList+markRequestHandled) ⇒ `Promise`
+ - [`.reclaimRequest(request)`](#RequestList+reclaimRequest) ⇒ `Promise`
+ - [`.length()`](#RequestList+length) ⇒ `Number`
+ - [`.handledCount()`](#RequestList+handledCount) ⇒ `Number`
<a name="new_RequestList_new"></a>
diff --git a/docs/api/RequestQueue.md b/docs/api/RequestQueue.md
index 01cf3632c..a11cd7193 100644
--- a/docs/api/RequestQueue.md
+++ b/docs/api/RequestQueue.md
@@ -57,8 +57,8 @@ const queueWithName = await Apify.openRequestQueue("some-name");
await queue.addRequest({ url: "http://example.com/aaa" });
await queue.addRequest({ url: "http://example.com/bbb" });
await queue.addRequest(
- { url: "http://example.com/foo/bar" },
- { forefront: true }
+ { url: "http://example.com/foo/bar" },
+ { forefront: true }
);
// Get requests from queue
@@ -73,17 +73,17 @@ await queue.markRequestHandled(request1);
await queue.reclaimRequest(request2);
```
-- [RequestQueue](requestqueue)
- - [`.addRequest(request, [options])`](#RequestQueue+addRequest) ⇒ [`QueueOperationInfo`](../typedefs/queueoperationinfo)
- - [`.getRequest(requestId)`](#RequestQueue+getRequest) ⇒ [`Promise<Request>`](request)
- - [`.fetchNextRequest()`](#RequestQueue+fetchNextRequest) ⇒ [`Promise<Request>`](request)
- - [`.markRequestHandled(request)`](#RequestQueue+markRequestHandled) ⇒ [`Promise<QueueOperationInfo>`](../typedefs/queueoperationinfo)
- - [`.reclaimRequest(request, [options])`](#RequestQueue+reclaimRequest) ⇒ [`Promise<QueueOperationInfo>`](../typedefs/queueoperationinfo)
- - [`.isEmpty()`](#RequestQueue+isEmpty) ⇒ `Promise<Boolean>`
- - [`.isFinished()`](#RequestQueue+isFinished) ⇒ `Promise<Boolean>`
- - [`.delete()`](#RequestQueue+delete) ⇒ `Promise`
- - ~~[`.handledCount()`](#RequestQueue+handledCount) ⇒ `Promise<number>`~~
- - [`.getInfo()`](#RequestQueue+getInfo) ⇒ `Promise<Object>`
+- [RequestQueue](requestqueue)
+ - [`.addRequest(request, [options])`](#RequestQueue+addRequest) ⇒ [`QueueOperationInfo`](../typedefs/queueoperationinfo)
+ - [`.getRequest(requestId)`](#RequestQueue+getRequest) ⇒ [`Promise<Request>`](request)
+ - [`.fetchNextRequest()`](#RequestQueue+fetchNextRequest) ⇒ [`Promise<Request>`](request)
+ - [`.markRequestHandled(request)`](#RequestQueue+markRequestHandled) ⇒ [`Promise<QueueOperationInfo>`](../typedefs/queueoperationinfo)
+ - [`.reclaimRequest(request, [options])`](#RequestQueue+reclaimRequest) ⇒ [`Promise<QueueOperationInfo>`](../typedefs/queueoperationinfo)
+ - [`.isEmpty()`](#RequestQueue+isEmpty) ⇒ `Promise<Boolean>`
+ - [`.isFinished()`](#RequestQueue+isFinished) ⇒ `Promise<Boolean>`
+ - [`.delete()`](#RequestQueue+delete) ⇒ `Promise`
+ - ~~[`.handledCount()`](#RequestQueue+handledCount) ⇒ `Promise<number>`~~
+ - [`.getInfo()`](#RequestQueue+getInfo) ⇒ `Promise<Object>`
<a name="RequestQueue+addRequest"></a>
diff --git a/docs/api/Snapshotter.md b/docs/api/Snapshotter.md
index fffbc01e9..a69fcf600 100644
--- a/docs/api/Snapshotter.md
+++ b/docs/api/Snapshotter.md
@@ -28,14 +28,14 @@ Event loop becomes overloaded if it slows down by more than the `maxBlockedMilli
Client becomes overloaded when rate limit errors (429 - Too Many Requests),
typically received from the request queue, exceed the set limit within the set interval.
-- [Snapshotter](snapshotter)
- - [`new Snapshotter([options])`](#new_Snapshotter_new)
- - [`.start()`](#Snapshotter+start) ⇒ `Promise`
- - [`.stop()`](#Snapshotter+stop) ⇒ `Promise`
- - [`.getMemorySample([sampleDurationMillis])`](#Snapshotter+getMemorySample) ⇒ `Array`
- - [`.getEventLoopSample([sampleDurationMillis])`](#Snapshotter+getEventLoopSample) ⇒ `Array`
- - [`.getCpuSample([sampleDurationMillis])`](#Snapshotter+getCpuSample) ⇒ `Array`
- - [`.getClientSample(sampleDurationMillis)`](#Snapshotter+getClientSample) ⇒ `Array`
+- [Snapshotter](snapshotter)
+ - [`new Snapshotter([options])`](#new_Snapshotter_new)
+ - [`.start()`](#Snapshotter+start) ⇒ `Promise`
+ - [`.stop()`](#Snapshotter+stop) ⇒ `Promise`
+ - [`.getMemorySample([sampleDurationMillis])`](#Snapshotter+getMemorySample) ⇒ `Array`
+ - [`.getEventLoopSample([sampleDurationMillis])`](#Snapshotter+getEventLoopSample) ⇒ `Array`
+ - [`.getCpuSample([sampleDurationMillis])`](#Snapshotter+getCpuSample) ⇒ `Array`
+ - [`.getClientSample(sampleDurationMillis)`](#Snapshotter+getClientSample) ⇒ `Array`
<a name="new_Snapshotter_new"></a>
diff --git a/docs/api/SystemStatus.md b/docs/api/SystemStatus.md
index 53d8368d3..5ae7437ed 100644
--- a/docs/api/SystemStatus.md
+++ b/docs/api/SystemStatus.md
@@ -25,10 +25,10 @@ returns a boolean that represents the long-term status
of the system. It considers the full snapshot history available
in the [`Snapshotter`](snapshotter) instance.
-- [SystemStatus](systemstatus)
- - [`new SystemStatus([options])`](#new_SystemStatus_new)
- - [`.getCurrentStatus()`](#SystemStatus+getCurrentStatus) ⇒ `Object`
- - [`.getHistoricalStatus()`](#SystemStatus+getHistoricalStatus) ⇒ `Object`
+- [SystemStatus](systemstatus)
+ - [`new SystemStatus([options])`](#new_SystemStatus_new)
+ - [`.getCurrentStatus()`](#SystemStatus+getCurrentStatus) ⇒ `Object`
+ - [`.getHistoricalStatus()`](#SystemStatus+getHistoricalStatus) ⇒ `Object`
<a name="new_SystemStatus_new"></a>
diff --git a/docs/api/log.md b/docs/api/log.md
index 958d86372..d2734f89c 100644
--- a/docs/api/log.md
+++ b/docs/api/log.md
@@ -51,15 +51,15 @@ Another very useful way of setting the log level is by setting the `APIFY_LOG_LE
environment variable, such as `APIFY_LOG_LEVEL=DEBUG`. This way, no code changes
are necessary to turn on your debug messages and start debugging right away.
-- [`log`](#log) : `object`
- - [`.LEVELS`](#log.LEVELS) : `Object`
- - [`.setLevel(level)`](#log.setLevel)
- - [`.getLevel()`](#log.getLevel)
- - [`.debug(message, [data])`](#log.debug)
- - [`.info(message, [data])`](#log.info)
- - [`.warning(message, [data])`](#log.warning)
- - [`.error(message, [data])`](#log.error)
- - [`.exception(exception, [message], [data])`](#log.exception)
+- [`log`](#log) : `object`
+ - [`.LEVELS`](#log.LEVELS) : `Object`
+ - [`.setLevel(level)`](#log.setLevel)
+ - [`.getLevel()`](#log.getLevel)
+ - [`.debug(message, [data])`](#log.debug)
+ - [`.info(message, [data])`](#log.info)
+ - [`.warning(message, [data])`](#log.warning)
+ - [`.error(message, [data])`](#log.error)
+ - [`.exception(exception, [message], [data])`](#log.exception)
<a name="log.LEVELS"></a>
diff --git a/docs/api/puppeteer.md b/docs/api/puppeteer.md
index c088eb7d1..90f49e81f 100644
--- a/docs/api/puppeteer.md
+++ b/docs/api/puppeteer.md
@@ -23,18 +23,18 @@ await page.goto("https://www.example.com");
await puppeteer.injectJQuery(page);
```
-- [`puppeteer`](#puppeteer) : `object`
- - [`.enqueueLinksByClickingElements`](#puppeteer.enqueueLinksByClickingElements) ⇒ `Promise<Array<QueueOperationInfo>>`
- - [`.addInterceptRequestHandler`](#puppeteer.addInterceptRequestHandler) ⇒ `Promise`
- - [`.removeInterceptRequestHandler`](#puppeteer.removeInterceptRequestHandler) ⇒ `Promise`
- - [`.gotoExtended`](#puppeteer.gotoExtended) ⇒ `Promise<Response>`
- - [`.infiniteScroll`](#puppeteer.infiniteScroll) ⇒ `Promise`
- - [`.injectFile(page, filePath, [options])`](#puppeteer.injectFile) ⇒ `Promise`
- - [`.injectJQuery(page)`](#puppeteer.injectJQuery) ⇒ `Promise`
- - [`.injectUnderscore(page)`](#puppeteer.injectUnderscore) ⇒ `Promise`
- - [`.blockRequests(page, [options])`](#puppeteer.blockRequests) ⇒ `Promise`
- - ~~[`.cacheResponses(page, cache, responseUrlRules)`](#puppeteer.cacheResponses) ⇒ `Promise`~~
- - [`.compileScript(scriptString, context)`](#puppeteer.compileScript) ⇒ `function`
+- [`puppeteer`](#puppeteer) : `object`
+ - [`.enqueueLinksByClickingElements`](#puppeteer.enqueueLinksByClickingElements) ⇒ `Promise<Array<QueueOperationInfo>>`
+ - [`.addInterceptRequestHandler`](#puppeteer.addInterceptRequestHandler) ⇒ `Promise`
+ - [`.removeInterceptRequestHandler`](#puppeteer.removeInterceptRequestHandler) ⇒ `Promise`
+ - [`.gotoExtended`](#puppeteer.gotoExtended) ⇒ `Promise<Response>`
+ - [`.infiniteScroll`](#puppeteer.infiniteScroll) ⇒ `Promise`
+ - [`.injectFile(page, filePath, [options])`](#puppeteer.injectFile) ⇒ `Promise`
+ - [`.injectJQuery(page)`](#puppeteer.injectJQuery) ⇒ `Promise`
+ - [`.injectUnderscore(page)`](#puppeteer.injectUnderscore) ⇒ `Promise`
+ - [`.blockRequests(page, [options])`](#puppeteer.blockRequests) ⇒ `Promise`
+ - ~~[`.cacheResponses(page, cache, responseUrlRules)`](#puppeteer.cacheResponses) ⇒ `Promise`~~
+ - [`.compileScript(scriptString, context)`](#puppeteer.compileScript) ⇒ `function`
<a name="puppeteer.enqueueLinksByClickingElements"></a>
@@ -189,27 +189,27 @@ to any of the remaining handlers.
```javascript
// Replace images with placeholder.
await addInterceptRequestHandler(page, request => {
- if (request.resourceType() === "image") {
- return request.respond({
- statusCode: 200,
- contentType: "image/jpeg",
- body: placeholderImageBuffer
- });
- }
- return request.continue();
+ if (request.resourceType() === "image") {
+ return request.respond({
+ statusCode: 200,
+ contentType: "image/jpeg",
+ body: placeholderImageBuffer
+ });
+ }
+ return request.continue();
});
// Abort all the scripts.
await addInterceptRequestHandler(page, request => {
- if (request.resourceType() === "script") return request.abort();
- return request.continue();
+ if (request.resourceType() === "script") return request.abort();
+ return request.continue();
});
// Change requests to post.
await addInterceptRequestHandler(page, request => {
- return request.continue({
- method: "POST"
- });
+ return request.continue({
+ method: "POST"
+ });
});
await page.goto("http://example.com");
@@ -387,7 +387,7 @@ The injected jQuery will survive page navigations and reloads.
```javascript
await Apify.utils.puppeteer.injectJQuery(page);
const title = await page.evaluate(() => {
- return $("head title").text();
+ return $("head title").text();
});
```
@@ -426,7 +426,7 @@ The injected Underscore will survive page navigations and reloads.
```javascript
await Apify.utils.puppeteer.injectUnderscore(page);
const escapedHtml = await page.evaluate(() => {
- return _.escape("<h1>Hello</h1>");
+ return _.escape("<h1>Hello</h1>");
});
```
@@ -480,7 +480,7 @@ const page = await browser.newPage();
// Block all requests to URLs that include `adsbygoogle.js` and also all defaults.
await Apify.utils.puppeteer.blockRequests(page, {
- extraUrlPatterns: ["adsbygoogle.js"]
+ extraUrlPatterns: ["adsbygoogle.js"]
});
await page.goto("https://cnn.com");
diff --git a/docs/api/social.md b/docs/api/social.md
index 596581e8b..9d8be4ba1 100644
--- a/docs/api/social.md
+++ b/docs/api/social.md
@@ -14,26 +14,26 @@ from text, URLs and and HTML documents.
const Apify = require("apify");
const emails = Apify.utils.social.emailsFromText(
);
```
-- [`social`](#social) : `object`
- - [`.LINKEDIN_REGEX`](#social.LINKEDIN_REGEX) : `RegExp`
- - [`.LINKEDIN_REGEX_GLOBAL`](#social.LINKEDIN_REGEX_GLOBAL) : `RegExp`
- - [`.INSTAGRAM_REGEX`](#social.INSTAGRAM_REGEX) : `RegExp`
- - [`.INSTAGRAM_REGEX_GLOBAL`](#social.INSTAGRAM_REGEX_GLOBAL) : `RegExp`
- - [`.TWITTER_REGEX`](#social.TWITTER_REGEX) : `RegExp`
- - [`.TWITTER_REGEX_GLOBAL`](#social.TWITTER_REGEX_GLOBAL) : `RegExp`
- - [`.FACEBOOK_REGEX`](#social.FACEBOOK_REGEX) : `RegExp`
- - [`.FACEBOOK_REGEX_GLOBAL`](#social.FACEBOOK_REGEX_GLOBAL) : `RegExp`
- - [`.EMAIL_REGEX`](#social.EMAIL_REGEX) : `RegExp`
- - [`.EMAIL_REGEX_GLOBAL`](#social.EMAIL_REGEX_GLOBAL) : `RegExp`
- - [`.emailsFromText(text)`](#social.emailsFromText) ⇒ `Array<String>`
- - [`.emailsFromUrls(urls)`](#social.emailsFromUrls) ⇒ `Array<String>`
- - [`.phonesFromText(text)`](#social.phonesFromText) ⇒ `Array<String>`
- - [`.phonesFromUrls(urls)`](#social.phonesFromUrls) ⇒ `Array<String>`
- - [`.parseHandlesFromHtml(html, data)`](#social.parseHandlesFromHtml) ⇒ `*`
+- [`social`](#social) : `object`
+ - [`.LINKEDIN_REGEX`](#social.LINKEDIN_REGEX) : `RegExp`
+ - [`.LINKEDIN_REGEX_GLOBAL`](#social.LINKEDIN_REGEX_GLOBAL) : `RegExp`
+ - [`.INSTAGRAM_REGEX`](#social.INSTAGRAM_REGEX) : `RegExp`
+ - [`.INSTAGRAM_REGEX_GLOBAL`](#social.INSTAGRAM_REGEX_GLOBAL) : `RegExp`
+ - [`.TWITTER_REGEX`](#social.TWITTER_REGEX) : `RegExp`
+ - [`.TWITTER_REGEX_GLOBAL`](#social.TWITTER_REGEX_GLOBAL) : `RegExp`
+ - [`.FACEBOOK_REGEX`](#social.FACEBOOK_REGEX) : `RegExp`
+ - [`.FACEBOOK_REGEX_GLOBAL`](#social.FACEBOOK_REGEX_GLOBAL) : `RegExp`
+ - [`.EMAIL_REGEX`](#social.EMAIL_REGEX) : `RegExp`
+ - [`.EMAIL_REGEX_GLOBAL`](#social.EMAIL_REGEX_GLOBAL) : `RegExp`
+ - [`.emailsFromText(text)`](#social.emailsFromText) ⇒ `Array<String>`
+ - [`.emailsFromUrls(urls)`](#social.emailsFromUrls) ⇒ `Array<String>`
+ - [`.phonesFromText(text)`](#social.phonesFromText) ⇒ `Array<String>`
+ - [`.phonesFromUrls(urls)`](#social.phonesFromUrls) ⇒ `Array<String>`
+ - [`.parseHandlesFromHtml(html, data)`](#social.parseHandlesFromHtml) ⇒ `*`
<a name="social.LINKEDIN_REGEX"></a>
diff --git a/docs/api/utils.md b/docs/api/utils.md
index 9ee8d8cbc..5bbf7cda3 100644
--- a/docs/api/utils.md
+++ b/docs/api/utils.md
@@ -18,16 +18,16 @@ const Apify = require('apify');
await Apify.utils.sleep(1500);
```
-- [`utils`](#utils) : `object`
- - [`.enqueueLinks`](#utils.enqueueLinks) ⇒ `Promise<Array<QueueOperationInfo>>`
- - [`.sleep`](#utils.sleep) ⇒ `Promise`
- - [`.URL_NO_COMMAS_REGEX`](#utils.URL_NO_COMMAS_REGEX)
- - [`.URL_WITH_COMMAS_REGEX`](#utils.URL_WITH_COMMAS_REGEX)
- - [`.isDocker()`](#utils.isDocker) ⇒ `Promise`
- - [`.downloadListOfUrls(options)`](#utils.downloadListOfUrls) ⇒ `Promise<Array<String>>`
- - [`.extractUrls(options)`](#utils.extractUrls) ⇒ `Array<String>`
- - [`.getRandomUserAgent()`](#utils.getRandomUserAgent) ⇒ `String`
- - [`.htmlToText(html)`](#utils.htmlToText) ⇒ `String`
+- [`utils`](#utils) : `object`
+ - [`.enqueueLinks`](#utils.enqueueLinks) ⇒ `Promise<Array<QueueOperationInfo>>`
+ - [`.sleep`](#utils.sleep) ⇒ `Promise`
+ - [`.URL_NO_COMMAS_REGEX`](#utils.URL_NO_COMMAS_REGEX)
+ - [`.URL_WITH_COMMAS_REGEX`](#utils.URL_WITH_COMMAS_REGEX)
+ - [`.isDocker()`](#utils.isDocker) ⇒ `Promise`
+ - [`.downloadListOfUrls(options)`](#utils.downloadListOfUrls) ⇒ `Promise<Array<String>>`
+ - [`.extractUrls(options)`](#utils.extractUrls) ⇒ `Array<String>`
+ - [`.getRandomUserAgent()`](#utils.getRandomUserAgent) ⇒ `String`
+ - [`.htmlToText(html)`](#utils.htmlToText) ⇒ `String`
<a name="utils.enqueueLinks"></a>
@@ -53,13 +53,13 @@ const page = await browser.goto("https://www.example.com");
const requestQueue = await Apify.openRequestQueue();
await Apify.utils.enqueueLinks({
- page,
- requestQueue,
- selector: "a.product-detail",
- pseudoUrls: [
- "https://www.example.com/handbags/[.*]",
- "https://www.example.com/purses/[.*]"
- ]
+ page,
+ requestQueue,
+ selector: "a.product-detail",
+ pseudoUrls: [
+ "https://www.example.com/handbags/[.*]",
+ "https://www.example.com/purses/[.*]"
+ ]
});
```
diff --git a/docs/examples/BasicCrawler.md b/docs/examples/BasicCrawler.md
index d2b798887..cd9a4903b 100644
--- a/docs/examples/BasicCrawler.md
+++ b/docs/examples/BasicCrawler.md
@@ -21,44 +21,44 @@ const requestPromise = require("request-promise");
// Apify.main() function wraps the crawler logic (it is optional).
Apify.main(async () => {
- // Create and initialize an instance of the RequestList class that contains
- // a list of URLs to crawl. Here we use just a few hard-coded URLs.
- const requestList = new Apify.RequestList({
- sources: [
- { url: "http://www.google.com/" },
- { url: "http://www.example.com/" },
- { url: "http://www.bing.com/" },
- { url: "http://www.wikipedia.com/" }
- ]
- });
- await requestList.initialize();
+ // Create and initialize an instance of the RequestList class that contains
+ // a list of URLs to crawl. Here we use just a few hard-coded URLs.
+ const requestList = new Apify.RequestList({
+ sources: [
+ { url: "http://www.google.com/" },
+ { url: "http://www.example.com/" },
+ { url: "http://www.bing.com/" },
+ { url: "http://www.wikipedia.com/" }
+ ]
+ });
+ await requestList.initialize();
- // Create a BasicCrawler - the simplest crawler that enables
- // users to implement the crawling logic themselves.
- const crawler = new Apify.BasicCrawler({
- // Let the crawler fetch URLs from our list.
- requestList,
+ // Create a BasicCrawler - the simplest crawler that enables
+ // users to implement the crawling logic themselves.
+ const crawler = new Apify.BasicCrawler({
+ // Let the crawler fetch URLs from our list.
+ requestList,
- // This function will be called for each URL to crawl.
- // The 'request' option is an instance of the Request class, which contains
- // information such as URL and HTTP method, as supplied by the RequestList.
- handleRequestFunction: async ({ request }) => {
- console.log(`Processing ${request.url}...`);
+ // This function will be called for each URL to crawl.
+ // The 'request' option is an instance of the Request class, which contains
+ // information such as URL and HTTP method, as supplied by the RequestList.
+ handleRequestFunction: async ({ request }) => {
+ console.log(`Processing ${request.url}...`);
- // Fetch the page HTML
- const html = await requestPromise(request.url);
+ // Fetch the page HTML
+ const html = await requestPromise(request.url);
- // Store the HTML and URL to the default dataset.
- await Apify.pushData({
- url: request.url,
- html
- });
- }
- });
+ // Store the HTML and URL to the default dataset.
+ await Apify.pushData({
+ url: request.url,
+ html
+ });
+ }
+ });
- // Run the crawler and wait for it to finish.
- await crawler.run();
+ // Run the crawler and wait for it to finish.
+ await crawler.run();
- console.log("Crawler finished.");
+ console.log("Crawler finished.");
});
```
diff --git a/docs/examples/CallActor.md b/docs/examples/CallActor.md
index 3087a1c60..99f4222a8 100644
--- a/docs/examples/CallActor.md
+++ b/docs/examples/CallActor.md
@@ -23,33 +23,33 @@ on the source tab of your actor configuration.
const Apify = require("apify");
Apify.main(async () => {
- // Launch the web browser.
- const browser = await Apify.launchPuppeteer();
-
- console.log("Obtaining email address...");
- const user = await Apify.client.users.getUser();
-
- // Load Kraken.com charts and get last traded price of BTC
- console.log("Extracting data from kraken.com...");
- const page = await browser.newPage();
- await page.goto("https://www.kraken.com/charts");
- const tradedPricesHtml = await page.$eval(
- "#ticker-top ul",
- el => el.outerHTML
- );
-
- // Send prices to your email. For that, you can use an actor we already
- // have available on the platform under the name: apify/send-mail.
- // The second parameter to the Apify.call() invocation is the actor's
- // desired input. You can find the required input parameters by checking
- // the actor's documentation page: https://apify.com/apify/send-mail
- console.log(`Sending email to ${user.email}...`);
- await Apify.call("apify/send-mail", {
- to: user.email,
- subject: "Kraken.com BTC",
- html: `<h1>Kraken.com BTC</h1>${tradedPricesHtml}`
- });
-
- console.log("Email sent. Good luck!");
+ // Launch the web browser.
+ const browser = await Apify.launchPuppeteer();
+
+ console.log("Obtaining email address...");
+ const user = await Apify.client.users.getUser();
+
+ // Load Kraken.com charts and get last traded price of BTC
+ console.log("Extracting data from kraken.com...");
+ const page = await browser.newPage();
+ await page.goto("https://www.kraken.com/charts");
+ const tradedPricesHtml = await page.$eval(
+ "#ticker-top ul",
+ el => el.outerHTML
+ );
+
+ // Send prices to your email. For that, you can use an actor we already
+ // have available on the platform under the name: apify/send-mail.
+ // The second parameter to the Apify.call() invocation is the actor's
+ // desired input. You can find the required input parameters by checking
+ // the actor's documentation page: https://apify.com/apify/send-mail
+ console.log(`Sending email to ${user.email}...`);
+ await Apify.call("apify/send-mail", {
+ to: user.email,
+ subject: "Kraken.com BTC",
+ html: `<h1>Kraken.com BTC</h1>${tradedPricesHtml}`
+ });
+
+ console.log("Email sent. Good luck!");
});
```
diff --git a/docs/examples/CheerioCrawler.md b/docs/examples/CheerioCrawler.md
index 68e240f47..e5e88ac1d 100644
--- a/docs/examples/CheerioCrawler.md
+++ b/docs/examples/CheerioCrawler.md
@@ -21,71 +21,71 @@ log.setLevel(log.LEVELS.WARNING);
// A link to a list of Fortune 500 companies' websites available on GitHub.
const CSV_LINK =
- "https://gist.githubusercontent.com/hrbrmstr/ae574201af3de035c684/raw/f1000.csv";
+ "https://gist.githubusercontent.com/hrbrmstr/ae574201af3de035c684/raw/f1000.csv";
// Apify.main() function wraps the crawler logic (it is optional).
Apify.main(async () => {
- // Create an instance of the RequestList class that contains a list of URLs to crawl.
- // Here we download and parse the list of URLs from an external file.
- const requestList = new Apify.RequestList({
- sources: [{ requestsFromUrl: CSV_LINK }]
- });
- await requestList.initialize();
-
- // Create an instance of the CheerioCrawler class - a crawler
- // that automatically loads the URLs and parses their HTML using the cheerio library.
- const crawler = new Apify.CheerioCrawler({
- // Let the crawler fetch URLs from our list.
- requestList,
-
- // The crawler downloads and processes the web pages in parallel, with a concurrency
- // automatically managed based on the available system memory and CPU (see AutoscaledPool class).
- // Here we define some hard limits for the concurrency.
- minConcurrency: 10,
- maxConcurrency: 50,
-
- // On error, retry each page at most once.
- maxRequestRetries: 1,
-
- // Increase the timeout for processing of each page.
- handlePageTimeoutSecs: 60,
-
- // This function will be called for each URL to crawl.
- // It accepts a single parameter, which is an object with the following fields:
- // - request: an instance of the Request class with information such as URL and HTTP method
- // - html: contains raw HTML of the page
- // - $: the cheerio object containing parsed HTML
- handlePageFunction: async ({ request, html, $ }) => {
- console.log(`Processing ${request.url}...`);
-
- // Extract data from the page using cheerio.
- const title = $("title").text();
- const h1texts = [];
- $("h1").each((index, el) => {
- h1texts.push({
- text: $(el).text()
- });
- });
-
- // Store the results to the default dataset. In local configuration,
- // the data will be stored as JSON files in ./apify_storage/datasets/default
- await Apify.pushData({
- url: request.url,
- title,
- h1texts,
- html
- });
- },
-
- // This function is called if the page processing failed more than maxRequestRetries+1 times.
- handleFailedRequestFunction: async ({ request }) => {
- console.log(`Request ${request.url} failed twice.`);
- }
- });
-
- // Run the crawler and wait for it to finish.
- await crawler.run();
-
- console.log("Crawler finished.");
+ // Create an instance of the RequestList class that contains a list of URLs to crawl.
+ // Here we download and parse the list of URLs from an external file.
+ const requestList = new Apify.RequestList({
+ sources: [{ requestsFromUrl: CSV_LINK }]
+ });
+ await requestList.initialize();
+
+ // Create an instance of the CheerioCrawler class - a crawler
+ // that automatically loads the URLs and parses their HTML using the cheerio library.
+ const crawler = new Apify.CheerioCrawler({
+ // Let the crawler fetch URLs from our list.
+ requestList,
+
+ // The crawler downloads and processes the web pages in parallel, with a concurrency
+ // automatically managed based on the available system memory and CPU (see AutoscaledPool class).
+ // Here we define some hard limits for the concurrency.
+ minConcurrency: 10,
+ maxConcurrency: 50,
+
+ // On error, retry each page at most once.
+ maxRequestRetries: 1,
+
+ // Increase the timeout for processing of each page.
+ handlePageTimeoutSecs: 60,
+
+ // This function will be called for each URL to crawl.
+ // It accepts a single parameter, which is an object with the following fields:
+ // - request: an instance of the Request class with information such as URL and HTTP method
+ // - html: contains raw HTML of the page
+ // - $: the cheerio object containing parsed HTML
+ handlePageFunction: async ({ request, html, $ }) => {
+ console.log(`Processing ${request.url}...`);
+
+ // Extract data from the page using cheerio.
+ const title = $("title").text();
+ const h1texts = [];
+ $("h1").each((index, el) => {
+ h1texts.push({
+ text: $(el).text()
+ });
+ });
+
+ // Store the results to the default dataset. In local configuration,
+ // the data will be stored as JSON files in ./apify_storage/datasets/default
+ await Apify.pushData({
+ url: request.url,
+ title,
+ h1texts,
+ html
+ });
+ },
+
+ // This function is called if the page processing failed more than maxRequestRetries+1 times.
+ handleFailedRequestFunction: async ({ request }) => {
+ console.log(`Request ${request.url} failed twice.`);
+ }
+ });
+
+ // Run the crawler and wait for it to finish.
+ await crawler.run();
+
+ console.log("Crawler finished.");
});
```
diff --git a/docs/examples/HelloWorld.md b/docs/examples/HelloWorld.md
index 41ddc60ce..842669d70 100644
--- a/docs/examples/HelloWorld.md
+++ b/docs/examples/HelloWorld.md
@@ -12,26 +12,26 @@ on the source tab of your actor configuration.
const Apify = require("apify");
Apify.main(async () => {
- const requestQueue = await Apify.openRequestQueue();
- await requestQueue.addRequest({ url: "https://www.iana.org/" });
- const pseudoUrls = [new Apify.PseudoUrl("https://www.iana.org/[.*]")];
+ const requestQueue = await Apify.openRequestQueue();
+ await requestQueue.addRequest({ url: "https://www.iana.org/" });
+ const pseudoUrls = [new Apify.PseudoUrl("https://www.iana.org/[.*]")];
- const crawler = new Apify.PuppeteerCrawler({
- requestQueue,
- handlePageFunction: async ({ request, page }) => {
- const title = await page.title();
- console.log(`Title of ${request.url}: ${title}`);
- await Apify.utils.enqueueLinks({
- page,
- selector: "a",
- pseudoUrls,
- requestQueue
- });
- },
- maxRequestsPerCrawl: 100,
- maxConcurrency: 10
- });
+ const crawler = new Apify.PuppeteerCrawler({
+ requestQueue,
+ handlePageFunction: async ({ request, page }) => {
+ const title = await page.title();
+ console.log(`Title of ${request.url}: ${title}`);
+ await Apify.utils.enqueueLinks({
+ page,
+ selector: "a",
+ pseudoUrls,
+ requestQueue
+ });
+ },
+ maxRequestsPerCrawl: 100,
+ maxConcurrency: 10
+ });
- await crawler.run();
+ await crawler.run();
});
```
diff --git a/docs/examples/PuppeteerCrawler.md b/docs/examples/PuppeteerCrawler.md
index 1810d48fc..f3043ee00 100644
--- a/docs/examples/PuppeteerCrawler.md
+++ b/docs/examples/PuppeteerCrawler.md
@@ -17,77 +17,76 @@ on the source tab of your actor configuration.
const Apify = require("apify");
Apify.main(async () => {
- // Apify.openRequestQueue() is a factory to get a preconfigured RequestQueue instance.
- // We add our first request to it - the initial page the crawler will visit.
- const requestQueue = await Apify.openRequestQueue();
- await requestQueue.addRequest({ url: "https://news.ycombinator.com/" });
-
- // Create an instance of the PuppeteerCrawler class - a crawler
- // that automatically loads the URLs in headless Chrome / Puppeteer.
- const crawler = new Apify.PuppeteerCrawler({
+ // Apify.openRequestQueue() is a factory to get a preconfigured RequestQueue instance.
+ // We add our first request to it - the initial page the crawler will visit.
+ const requestQueue = await Apify.openRequestQueue();
+ await requestQueue.addRequest({ url: "https://news.ycombinator.com/" });
+
+ // Create an instance of the PuppeteerCrawler class - a crawler
+ // that automatically loads the URLs in headless Chrome / Puppeteer.
+ const crawler = new Apify.PuppeteerCrawler({
+ requestQueue,
+
+ // Here you can set options that are passed to the Apify.launchPuppeteer() function.
+ launchPuppeteerOptions: {
+ // For example, by adding "slowMo" you'll slow down Puppeteer operations to simplify debugging
+ // slowMo: 500,
+ },
+
+ // Stop crawling after several pages
+ maxRequestsPerCrawl: 10,
+
+ // This function will be called for each URL to crawl.
+ // Here you can write the Puppeteer scripts you are familiar with,
+ // with the exception that browsers and pages are automatically managed by the Apify SDK.
+ // The function accepts a single parameter, which is an object with the following fields:
+ // - request: an instance of the Request class with information such as URL and HTTP method
+ // - page: Puppeteer's Page object (see https://pptr.dev/#show=api-class-page)
+ handlePageFunction: async ({ request, page }) => {
+ console.log(`Processing ${request.url}...`);
+
+ // A function to be evaluated by Puppeteer within the browser context.
+ const pageFunction = $posts => {
+ const data = [];
+
+ // We're getting the title, rank and URL of each post on Hacker News.
+ $posts.forEach($post => {
+ data.push({
+ title: $post.querySelector(".title a").innerText,
+ rank: $post.querySelector(".rank").innerText,
+ href: $post.querySelector(".title a").href
+ });
+ });
+
+ return data;
+ };
+ const data = await page.$$eval(".athing", pageFunction);
+
+ // Store the results to the default dataset.
+ await Apify.pushData(data);
+
+ // Find a link to the next page and enqueue it if it exists.
+ const infos = await Apify.utils.enqueueLinks({
+ page,
requestQueue,
+ selector: ".morelink"
+ });
- // Here you can set options that are passed to the Apify.launchPuppeteer() function.
- launchPuppeteerOptions: {
- // For example, by adding "slowMo" you'll slow down Puppeteer operations to simplify debugging
- // slowMo: 500,
- },
-
- // Stop crawling after several pages
- maxRequestsPerCrawl: 10,
-
- // This function will be called for each URL to crawl.
- // Here you can write the Puppeteer scripts you are familiar with,
- // with the exception that browsers and pages are automatically managed by the Apify SDK.
- // The function accepts a single parameter, which is an object with the following fields:
- // - request: an instance of the Request class with information such as URL and HTTP method
- // - page: Puppeteer's Page object (see https://pptr.dev/#show=api-class-page)
- handlePageFunction: async ({ request, page }) => {
- console.log(`Processing ${request.url}...`);
-
- // A function to be evaluated by Puppeteer within the browser context.
- const pageFunction = $posts => {
- const data = [];
-
- // We're getting the title, rank and URL of each post on Hacker News.
- $posts.forEach($post => {
- data.push({
- title: $post.querySelector(".title a").innerText,
- rank: $post.querySelector(".rank").innerText,
- href: $post.querySelector(".title a").href
- });
- });
-
- return data;
- };
- const data = await page.$$eval(".athing", pageFunction);
-
- // Store the results to the default dataset.
- await Apify.pushData(data);
-
- // Find a link to the next page and enqueue it if it exists.
- const infos = await Apify.utils.enqueueLinks({
- page,
- requestQueue,
- selector: ".morelink"
- });
-
- if (infos.length === 0)
- console.log(`${request.url} is the last page!`);
- },
-
- // This function is called if the page processing failed more than maxRequestRetries+1 times.
- handleFailedRequestFunction: async ({ request }) => {
- console.log(`Request ${request.url} failed too many times`);
- await Apify.pushData({
- "#debug": Apify.utils.createRequestDebugInfo(request)
- });
- }
- });
-
- // Run the crawler and wait for it to finish.
- await crawler.run();
-
- console.log("Crawler finished.");
+ if (infos.length === 0) console.log(`${request.url} is the last page!`);
+ },
+
+ // This function is called if the page processing failed more than maxRequestRetries+1 times.
+ handleFailedRequestFunction: async ({ request }) => {
+ console.log(`Request ${request.url} failed too many times`);
+ await Apify.pushData({
+ "#debug": Apify.utils.createRequestDebugInfo(request)
+ });
+ }
+ });
+
+ // Run the crawler and wait for it to finish.
+ await crawler.run();
+
+ console.log("Crawler finished.");
});
```
diff --git a/docs/examples/PuppeteerSitemap.md b/docs/examples/PuppeteerSitemap.md
index 8846dc2e1..68ed50425 100644
--- a/docs/examples/PuppeteerSitemap.md
+++ b/docs/examples/PuppeteerSitemap.md
@@ -15,26 +15,26 @@ on the source tab of your actor configuration.
const Apify = require("apify");
Apify.main(async () => {
- const requestList = new Apify.RequestList({
- sources: [
- { requestsFromUrl: "https://edition.cnn.com/sitemaps/cnn/news.xml" }
- ]
- });
- await requestList.initialize();
+ const requestList = new Apify.RequestList({
+ sources: [
+ { requestsFromUrl: "https://edition.cnn.com/sitemaps/cnn/news.xml" }
+ ]
+ });
+ await requestList.initialize();
- const crawler = new Apify.PuppeteerCrawler({
- requestList,
- handlePageFunction: async ({ page, request }) => {
- console.log(`Processing ${request.url}...`);
- await Apify.pushData({
- url: request.url,
- title: await page.title(),
- html: await page.content()
- });
- }
- });
+ const crawler = new Apify.PuppeteerCrawler({
+ requestList,
+ handlePageFunction: async ({ page, request }) => {
+ console.log(`Processing ${request.url}...`);
+ await Apify.pushData({
+ url: request.url,
+ title: await page.title(),
+ html: await page.content()
+ });
+ }
+ });
- await crawler.run();
- console.log("Done.");
+ await crawler.run();
+ console.log("Done.");
});
```
diff --git a/docs/examples/PuppeteerWithProxy.md b/docs/examples/PuppeteerWithProxy.md
index f37cc945b..00c920d54 100644
--- a/docs/examples/PuppeteerWithProxy.md
+++ b/docs/examples/PuppeteerWithProxy.md
@@ -18,26 +18,26 @@ on the source tab of your actor configuration.
const Apify = require("apify");
Apify.main(async () => {
- // Apify.launchPuppeteer() is similar to Puppeteer's launch() function.
- // It accepts the same parameters and returns a preconfigured Puppeteer.Browser instance.
- // Moreover, it accepts several additional options, such as useApifyProxy.
- const options = {
- useApifyProxy: true
- };
- const browser = await Apify.launchPuppeteer(options);
-
- console.log("Running Puppeteer script...");
-
- // Proceed with a plain Puppeteer script.
- const page = await browser.newPage();
- const url = "https://en.wikipedia.org/wiki/Main_Page";
- await page.goto(url);
- const title = await page.title();
-
- console.log(`Page title: ${title}`);
-
- // Cleaning up after yourself is always good.
- await browser.close();
- console.log("Puppeteer closed.");
+ // Apify.launchPuppeteer() is similar to Puppeteer's launch() function.
+ // It accepts the same parameters and returns a preconfigured Puppeteer.Browser instance.
+ // Moreover, it accepts several additional options, such as useApifyProxy.
+ const options = {
+ useApifyProxy: true
+ };
+ const browser = await Apify.launchPuppeteer(options);
+
+ console.log("Running Puppeteer script...");
+
+ // Proceed with a plain Puppeteer script.
+ const page = await browser.newPage();
+ const url = "https://en.wikipedia.org/wiki/Main_Page";
+ await page.goto(url);
+ const title = await page.title();
+
+ console.log(`Page title: ${title}`);
+
+ // Cleaning up after yourself is always good.
+ await browser.close();
+ console.log("Puppeteer closed.");
});
```
diff --git a/docs/examples/Screenshots.md b/docs/examples/Screenshots.md
index 65a390932..a244b8111 100644
--- a/docs/examples/Screenshots.md
+++ b/docs/examples/Screenshots.md
@@ -17,10 +17,10 @@ In local configuration, the input is stored in the default key-value store's dir
```json
{
- "sources": [
- { "url": "https://www.google.com" },
- { "url": "https://www.duckduckgo.com" }
- ]
+ "sources": [
+ { "url": "https://www.google.com" },
+ { "url": "https://www.duckduckgo.com" }
+ ]
}
```
@@ -37,40 +37,38 @@ on the source tab of your actor configuration.
const Apify = require("apify");
Apify.main(async () => {
- // Read the actor input configuration containing the URLs for the screenshot.
- // By convention, the input is present in the actor's default key-value store under the "INPUT" key.
- const input = await Apify.getInput();
- if (!input) throw new Error("Have you passed the correct INPUT ?");
+ // Read the actor input configuration containing the URLs for the screenshot.
+ // By convention, the input is present in the actor's default key-value store under the "INPUT" key.
+ const input = await Apify.getInput();
+ if (!input) throw new Error("Have you passed the correct INPUT ?");
- const { sources } = input;
+ const { sources } = input;
- const requestList = new Apify.RequestList({ sources });
- await requestList.initialize();
+ const requestList = new Apify.RequestList({ sources });
+ await requestList.initialize();
- const crawler = new Apify.PuppeteerCrawler({
- requestList,
- handlePageFunction: async ({ page, request }) => {
- console.log(`Processing ${request.url}...`);
+ const crawler = new Apify.PuppeteerCrawler({
+ requestList,
+ handlePageFunction: async ({ page, request }) => {
+ console.log(`Processing ${request.url}...`);
- // This is a Puppeteer function that takes a screenshot of the page and returns its buffer.
- const screenshotBuffer = await page.screenshot();
+ // This is a Puppeteer function that takes a screenshot of the page and returns its buffer.
+ const screenshotBuffer = await page.screenshot();
- // The record key may only include the following characters: a-zA-Z0-9!-_.'()
- const key = request.url.replace(/[:/]/g, "_");
+ // The record key may only include the following characters: a-zA-Z0-9!-_.'()
+ const key = request.url.replace(/[:/]/g, "_");
- // Save the screenshot. Choosing the right content type will automatically
- // assign the local file the right extension, in this case .png.
- // The screenshots will be stored in ./apify_storage/key_value_stores/default/
- await Apify.setValue(key, screenshotBuffer, {
- contentType: "image/png"
- });
- console.log(`Screenshot of ${request.url} saved.`);
- }
- });
+ // Save the screenshot. Choosing the right content type will automatically
+ // assign the local file the right extension, in this case .png.
+ // The screenshots will be stored in ./apify_storage/key_value_stores/default/
+ await Apify.setValue(key, screenshotBuffer, { contentType: "image/png" });
+ console.log(`Screenshot of ${request.url} saved.`);
+ }
+ });
- // Run crawler.
- await crawler.run();
+ // Run crawler.
+ await crawler.run();
- console.log("Crawler finished.");
+ console.log("Crawler finished.");
});
```
diff --git a/docs/examples/SynchronousRun.md b/docs/examples/SynchronousRun.md
index a45a7ebe8..356ba4655 100644
--- a/docs/examples/SynchronousRun.md
+++ b/docs/examples/SynchronousRun.md
@@ -25,29 +25,29 @@ on the source tab of your actor configuration.
const Apify = require("apify");
Apify.main(async () => {
- // Launch web browser.
- const browser = await Apify.launchPuppeteer();
-
- // Load http://goldengatebridge75.org/news/webcam.html and get an IFRAME with the webcam stream
- console.log("Opening web page...");
- const page = await browser.newPage();
- await page.goto("http://goldengatebridge75.org/news/webcam.html");
- const iframe = (await page.frames()).pop();
-
- // Get webcam image element handle.
- const imageElementHandle = await iframe.$(".VideoColm img");
-
- // Give the webcam image some time to load.
- console.log("Waiting for page to load...");
- await Apify.utils.sleep(3000);
-
- // Get a screenshot of that image.
- const imageBuffer = await imageElementHandle.screenshot();
- console.log("Screenshot captured.");
-
- // Save the screenshot as the actor's output. By convention, similarly to "INPUT",
- // the actor's output is stored in the default key-value store under the "OUTPUT" key.
- await Apify.setValue("OUTPUT", imageBuffer, { contentType: "image/jpeg" });
- console.log("Actor finished.");
+ // Launch web browser.
+ const browser = await Apify.launchPuppeteer();
+
+ // Load http://goldengatebridge75.org/news/webcam.html and get an IFRAME with the webcam stream
+ console.log("Opening web page...");
+ const page = await browser.newPage();
+ await page.goto("http://goldengatebridge75.org/news/webcam.html");
+ const iframe = (await page.frames()).pop();
+
+ // Get webcam image element handle.
+ const imageElementHandle = await iframe.$(".VideoColm img");
+
+ // Give the webcam image some time to load.
+ console.log("Waiting for page to load...");
+ await Apify.utils.sleep(3000);
+
+ // Get a screenshot of that image.
+ const imageBuffer = await imageElementHandle.screenshot();
+ console.log("Screenshot captured.");
+
+ // Save the screenshot as the actor's output. By convention, similarly to "INPUT",
+ // the actor's output is stored in the default key-value store under the "OUTPUT" key.
+ await Apify.setValue("OUTPUT", imageBuffer, { contentType: "image/jpeg" });
+ console.log("Actor finished.");
});
```