Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apify

Package Overview
Dependencies
Maintainers
0
Versions
997
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apify

The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.

  • 3.2.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.9K
decreased by-5.67%
Maintainers
0
Weekly downloads
 
Created
Source

Apify SDK

npm version Downloads Chat on discord Build Status

Apify SDK provides the tools required to run your own Apify Actors. The crawlers and scraping related tools, previously included in Apify SDK (v2), have been split into a brand-new module - crawlee, while keeping the Apify specific parts in this module.

Would you like to work with us on Crawlee, Apify SDK or similar projects? We are hiring Node.js engineers.

Upgrading from v2

A lot of things have changed since version 2 of the Apify SDK, including the split of the crawlers to the new crawlee module. We've written a guide to help you easily migrate from v2 to v3. Visit the Upgrading Guide to find out what changes you need to make (especially the section related to this very Apify SDK), and, if you encounter any issues, join our Discord server for help!

Quick Start

This short tutorial will set you up to start using Apify SDK in a minute or two. If you want to learn more, proceed to the Apify Platform guide that will take you step by step through running your Actor on Apify's platform.

Apify SDK requires Node.js 16 or later. Add Apify SDK to any Node.js project by running:

npm install apify crawlee playwright

For this example, we'll also install the crawlee module, as it now provides the crawlers that were previously exported by Apify SDK. If you don't plan to use crawlers in your Actors, then you don't need to install it. Keep in mind that neither playwright nor puppeteer are bundled with crawlee in order to reduce install size and allow greater flexibility. That's why we manually install it with NPM. You can choose one, both, or neither.

There are two ways to initialize your Actor: by using the Actor.main() function you're probably used to, or by calling Actor.init() and Actor.exit() manually. We prefer explicitly calling init and exit.

Using Actor.init() and Actor.exit()

import { Actor } from 'apify';
import { PlaywrightCrawler } from 'crawlee';

await Actor.init()

const crawler = new PlaywrightCrawler({
    async requestHandler({ request, page, enqueueLinks }) {
        // Extract HTML title of the page.
        const title = await page.title();
        console.log(`Title of ${request.url}: ${title}`);

        // Add URLs that point to the same hostname.
        await enqueueLinks();
    },
});

await crawler.run(['https://crawlee.dev/']);

await Actor.exit();

Using Actor.main()

import { Actor } from 'apify';
import { PlaywrightCrawler } from 'crawlee';

await Actor.main(async () => {
    const crawler = new PlaywrightCrawler({
        async requestHandler({ request, page, enqueueLinks }) {
            // Extract HTML title of the page.
            const title = await page.title();
            console.log(`Title of ${request.url}: ${title}`);

            // Add URLs that point to the same hostname.
            await enqueueLinks();
        },
    });

    await crawler.run(['https://crawlee.dev/']);
});

Support

If you find any bug or issue with the Apify SDK, please submit an issue on GitHub. For questions, you can ask on Stack Overflow or contact support@apify.com

Contributing

Your code contributions are welcome, and you'll be praised to eternity! If you have any ideas for improvements, either submit an issue or create a pull request. For contribution guidelines and the code of conduct, see CONTRIBUTING.md.

License

This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details.

Acknowledgments

Many thanks to Chema Balsas for giving up the apify package name on NPM and renaming his project to jsdocify.

Keywords

FAQs

Package last updated on 07 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc