{"id":18710732,"url":"https://github.com/apify/apify-sdk-v2","last_synced_at":"2025-11-03T16:34:12.819Z","repository":{"id":45355885,"uuid":"512823653","full_name":"apify/apify-sdk-v2","owner":"apify","description":"Snapshot of Apify SDK v2 + sdk.apify.com website. This project is no longer maintained. See the https://github.com/apify/apify-sdk-js repo instead!","archived":false,"fork":false,"pushed_at":"2022-08-19T10:29:47.000Z","size":20202,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-28T08:09:25.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-11T16:03:42.000Z","updated_at":"2023-05-18T06:08:52.000Z","dependencies_parsed_at":"2022-09-03T01:50:35.144Z","dependency_job_id":null,"html_url":"https://github.com/apify/apify-sdk-v2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fapify-sdk-v2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fapify-sdk-v2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fapify-sdk-v2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apify%2Fapify-sdk-v2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apify","download_url":"https://codeload.github.com/apify/apify-sdk-v2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239576248,"owners_count":19662106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T12:35:27.228Z","updated_at":"2025-11-03T16:34:12.791Z","avatar_url":"https://github.com/apify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apify SDK v2: The scalable web crawling and scraping library for JavaScript\n\n## This project is no longer maintained. Check out [Crawlee](https://crawlee.dev/docs/upgrading/upgrading-to-v3), the successor to Apify SDK v2!\n\n\u003c!-- Mirror this part to src/index.js --\u003e\n\n[![npm version](https://badge.fury.io/js/apify.svg)](https://www.npmjs.com/package/apify)\n[![Downloads](https://img.shields.io/npm/dm/apify.svg)](https://www.npmjs.com/package/apify)\n[![Chat on discord](https://img.shields.io/discord/801163717915574323?label=discord)](https://discord.gg/jyEM2PRvMU)\n[![Build Status](https://github.com/apify/apify-js/actions/workflows/test-and-release.yml/badge.svg?branch=master)](https://github.com/apify/apify-js/actions/workflows/test-and-release.yml)\n\nApify SDK simplifies the development of web crawlers, scrapers, data extractors and web automation jobs.\nIt provides tools to manage and automatically scale a pool of headless browsers,\nto maintain queues of URLs to crawl, store crawling results to a local filesystem or into the cloud,\nrotate proxies and much more.\nThe SDK is available as the [`apify`](https://www.npmjs.com/package/apify) NPM package.\nIt can be used either stand-alone in your own applications\nor in [actors](https://docs.apify.com/actor)\nrunning on the [Apify Cloud](https://apify.com/).\n\n**View full documentation, guides and examples on the [Apify SDK project website](https://sdk.apify.com)**\n\n\u003e Would you like to work with us on Apify SDK or similar projects? [We are hiring!](https://apify.com/jobs#senior-node.js-engineer)\n\n## Motivation\n\nThanks to tools like [Playwright](https://github.com/microsoft/playwright), [Puppeteer](https://github.com/puppeteer/puppeteer) or\n[Cheerio](https://www.npmjs.com/package/cheerio), it is easy to write Node.js code to extract data from web pages. But\neventually things will get complicated. For example, when you try to:\n\n-   Perform a deep crawl of an entire website using a persistent queue of URLs.\n-   Run your scraping code on a list of 100k URLs in a CSV file, without losing any data when your code crashes.\n-   Rotate proxies to hide your browser origin and keep user-like sessions.\n-   Disable browser fingerprinting protections used by websites.\n\nPython has [Scrapy](https://scrapy.org/) for these tasks, but there was no such library for **JavaScript, the language of\nthe web**. The use of JavaScript is natural, since the same language is used to write the scripts as well as the data extraction code running in a\nbrowser.\n\nThe goal of the Apify SDK is to fill this gap and provide a toolbox for generic web scraping, crawling and automation tasks in JavaScript. So don't\nreinvent the wheel every time you need data from the web, and focus on writing code specific to the target website, rather than developing\ncommonalities.\n\n## Overview\n\nThe Apify SDK is available as the [`apify`](https://www.npmjs.com/package/apify) NPM package and it provides the following tools:\n\n- [`CheerioCrawler`](https://sdk.apify.com/docs/api/cheerio-crawler) - Enables the parallel crawling of a large\n  number of web pages using the [cheerio](https://www.npmjs.com/package/cheerio) HTML parser. This is the most\n  efficient web crawler, but it does not work on websites that require JavaScript.\n\n- [`PuppeteerCrawler`](https://sdk.apify.com/docs/api/puppeteer-crawler) - Enables the parallel crawling of\n  a large number of web pages using the headless Chrome browser and [Puppeteer](https://github.com/puppeteer/puppeteer).\n  The pool of Chrome browsers is automatically scaled up and down based on available system resources.\n\n- [`PlaywrightCrawler`](https://sdk.apify.com/docs/api/playwright-crawler) - Unlike `PuppeteerCrawler`\n  you can use [Playwright](https://github.com/microsoft/playwright) to manage almost any headless browser.\n  It also provides a cleaner and more mature interface while keeping the ease of use and advanced features.\n\n- [`BasicCrawler`](https://sdk.apify.com/docs/api/basic-crawler) - Provides a simple framework for the parallel\n  crawling of web pages whose URLs are fed either from a static list or from a dynamic queue of URLs. This class\n  serves as a base for the more specialized crawlers above.\n\n- [`RequestList`](https://sdk.apify.com/docs/api/request-list) - Represents a list of URLs to crawl.\n  The URLs can be passed in code or in a text file hosted on the web. The list persists its state so that crawling\n  can resume when the Node.js process restarts.\n\n- [`RequestQueue`](https://sdk.apify.com/docs/api/request-queue) - Represents a queue of URLs to crawl,\n  which is stored either on a local filesystem or in the [Apify Cloud](https://apify.com). The queue is used\n  for deep crawling of websites, where you start with several URLs and then recursively follow links to other pages.\n  The data structure supports both breadth-first and depth-first crawling orders.\n\n- [`Dataset`](https://sdk.apify.com/docs/api/dataset) - Provides a store for structured data and enables their export\n  to formats like JSON, JSONL, CSV, XML, Excel or HTML. The data is stored on a local filesystem or in the Apify Cloud.\n  Datasets are useful for storing and sharing large tabular crawling results, such as a list of products or real estate offers.\n\n- [`KeyValueStore`](https://sdk.apify.com/docs/api/key-value-store) - A simple key-value store for arbitrary data\n  records or files, along with their MIME content type. It is ideal for saving screenshots of web pages, PDFs\n  or to persist the state of your crawlers. The data is stored on a local filesystem or in the Apify Cloud.\n\n- [`AutoscaledPool`](https://sdk.apify.com/docs/api/autoscaled-pool) - Runs asynchronous background tasks,\n  while automatically adjusting the concurrency based on free system memory and CPU usage. This is useful for running\n  web scraping tasks at the maximum capacity of the system.\n\n- [`Browser Utils`](https://sdk.apify.com/docs/api/puppeteer) - Provides several helper functions useful\n  for web scraping. For example, to inject jQuery into web pages or to hide browser origin.\n\nAdditionally, the package provides various helper functions to simplify running your code on the Apify Cloud and thus\ntake advantage of its pool of proxies, job scheduler, data storage, etc.\nFor more information, see the [Apify SDK Programmer's Reference](https://sdk.apify.com).\n\n## Quick Start\n\nThis short tutorial will set you up to start using Apify SDK in a minute or two.\nIf you want to learn more, proceed to the [Getting Started](https://sdk.apify.com/docs/guides/getting-started)\ntutorial that will take you step by step through creating your first scraper.\n\n### Local stand-alone usage\nApify SDK requires [Node.js](https://nodejs.org/en/) 15.10 or later.\nAdd Apify SDK to any Node.js project by running:\n\n```bash\nnpm install apify@^2.3.2 playwright\n```\n\n\u003e Neither `playwright` nor `puppeteer` are bundled with the SDK to reduce install size and allow greater\n\u003e flexibility. That's why we install it with NPM. You can choose one, both, or neither.\n\nRun the following example to perform a recursive crawl of a website using Playwright. For more examples showcasing various features of the Apify SDK,\n[see the Examples section of the documentation](https://sdk.apify.com/docs/examples/crawl-multiple-urls).\n\n```javascript\nconst Apify = require('apify');\n\n// Apify.main is a helper function, you don't need to use it.\nApify.main(async () =\u003e {\n    const requestQueue = await Apify.openRequestQueue();\n    // Choose the first URL to open.\n    await requestQueue.addRequest({ url: 'https://www.iana.org/' });\n\n    const crawler = new Apify.PlaywrightCrawler({\n        requestQueue,\n        handlePageFunction: async ({ request, page }) =\u003e {\n            // Extract HTML title of the page.\n            const title = await page.title();\n            console.log(`Title of ${request.url}: ${title}`);\n\n            // Add URLs that match the provided pattern.\n            await Apify.utils.enqueueLinks({\n                page,\n                requestQueue,\n                pseudoUrls: ['https://www.iana.org/[.*]'],\n            });\n        },\n    });\n\n    await crawler.run();\n});\n```\n\nWhen you run the example, you should see Apify SDK automating a Chrome browser.\n\n![Chrome Scrape](https://sdk.apify.com/img/chrome_scrape.gif)\n\nBy default, Apify SDK stores data to `./apify_storage` in the current working directory. You can override this behavior by setting either the\n`APIFY_LOCAL_STORAGE_DIR` or `APIFY_TOKEN` environment variable. For details, see [Environment variables](https://sdk.apify.com/docs/guides/environment-variables), [Request storage](https://sdk.apify.com/docs/guides/request-storage) and [Result storage](https://sdk.apify.com/docs/guides/result-storage).\n\n### Local usage with Apify command-line interface (CLI)\n\nTo avoid the need to set the environment variables manually, to create a boilerplate of your project, and to enable pushing and running your code on\nthe [Apify platform](https://sdk.apify.com/docs/guides/apify-platform), you can use the [Apify command-line interface (CLI)](https://github.com/apify/apify-cli) tool.\n\nInstall the CLI by running:\n\n```bash\nnpm -g install apify-cli\n```\n\nNow create a boilerplate of your new web crawling project by running:\n\n```bash\napify create my-hello-world\n```\n\nThe CLI will prompt you to select a project boilerplate template - just pick \"Hello world\". The tool will create a directory called `my-hello-world`\nwith a Node.js project files. You can run the project as follows:\n\n```bash\ncd my-hello-world\napify run\n```\n\nBy default, the crawling data will be stored in a local directory at `./apify_storage`. For example, the input JSON file for the actor is expected to\nbe in the default key-value store in `./apify_storage/key_value_stores/default/INPUT.json`.\n\nNow you can easily deploy your code to the Apify platform by running:\n\n```bash\napify login\n```\n\n```bash\napify push\n```\n\nYour script will be uploaded to the Apify platform and built there so that it can be run. For more information, view the\n[Apify Actor](https://docs.apify.com/cli) documentation.\n\n### Usage on the Apify platform\n\nYou can also develop your web scraping project in an online code editor directly on the [Apify platform](https://sdk.apify.com/docs/guides/apify-platform).\nYou'll need to have an Apify Account. Go to [Actors](https://console.apify.com/actors), page in the Apify Console, click \u003ci\u003eCreate new\u003c/i\u003e\nand then go to the \u003ci\u003eSource\u003c/i\u003e tab and start writing your code or paste one of the examples from the Examples section.\n\nFor more information, view the [Apify actors quick start guide](https://docs.apify.com/actor/quick-start).\n\n## Support\n\nIf you find any bug or issue with the Apify SDK, please [submit an issue on GitHub](https://github.com/apify/apify-js/issues).\nFor questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify) or contact support@apify.com\n\n## Contributing\n\nYour code contributions are welcome and you'll be praised to eternity!\nIf you have any ideas for improvements, either submit an issue or create a pull request.\nFor contribution guidelines and the code of conduct,\nsee [CONTRIBUTING.md](https://github.com/apify/apify-js/blob/master/CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the Apache License 2.0 -\nsee the [LICENSE.md](https://github.com/apify/apify-js/blob/master/LICENSE.md) file for details.\n\n## Acknowledgments\n\nMany thanks to [Chema Balsas](https://www.npmjs.com/~jbalsas) for giving up the `apify` package name\non NPM and renaming his project to [jsdocify](https://www.npmjs.com/package/jsdocify).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Fapify-sdk-v2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapify%2Fapify-sdk-v2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapify%2Fapify-sdk-v2/lists"}