Actor picture

Web Scraper


Crawls arbitrary websites using the Chrome browser and extracts data from pages using a provided JavaScript code. The actor supports both recursive crawling and lists of URLs and automatically manages concurrency for maximum performance. This is Apify's basic tool for web crawling and scraping.

No credit card required

Author's avatarApify
  • Modified
  • Users22,213
  • Runs62,428,663

To run the code examples, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token. For a more detailed explanation, please read about running actors via the API in Apify Docs.

const { ApifyClient } = require('apify-client');

// Initialize the ApifyClient with API token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',

// Prepare actor input
const input = {
    "runMode": "DEVELOPMENT",
    "startUrls": [
            "url": ""
    "linkSelector": "a[href]",
    "pseudoUrls": [
            "purl": "[(/[\\w-]+)?]"
    "pageFunction": // The function accepts a single argument: the "context" object.
    // For a complete list of its properties and functions,
    // see 
    async function pageFunction(context) {
        // This statement works as a breakpoint when you're trying to debug your code. Works only with Run mode: DEVELOPMENT!
        // debugger; 
        // jQuery is handy for finding DOM elements and extracting data from them.
        // To use it, make sure to enable the "Inject jQuery" option.
        const $ = context.jQuery;
        const pageTitle = $('title').first().text();
        // Print some information to actor log`URL: ${context.request.url}, TITLE: ${pageTitle}`);
        // Manually add a new page to the queue for scraping.
        context.enqueueRequest({ url: '' });
        // Return an object with the data extracted from the page.
        // It will be stored to the resulting dataset.
        return {
            url: context.request.url,
    "preNavigationHooks": `// We need to return array of (possibly async) functions here.
        // The functions accept two arguments: the "crawlingContext" object
        // and "gotoOptions".
            async (crawlingContext, gotoOptions) => {
                // ...
    "postNavigationHooks": `// We need to return array of (possibly async) functions here.
        // The functions accept a single argument: the "crawlingContext" object.
            async (crawlingContext) => {
                // ...
    "proxyConfiguration": {
        "useApifyProxy": false
    "initialCookies": [],
    "waitUntil": [
    "breakpointLocation": "NONE",
    "customData": {}

(async () => {
    // Run the actor and wait for it to finish
    const run = await"apify/web-scraper").call(input);

    // Fetch and print actor results from the run's dataset (if any)
    console.log('Results from dataset');
    const { items } = await client.dataset(run.defaultDatasetId).listItems();
    items.forEach((item) => {