Legacy PhantomJS Crawler avatar

Legacy PhantomJS Crawler

Try for free

No credit card required

Go to Store
Legacy PhantomJS Crawler

Legacy PhantomJS Crawler

apify/legacy-phantomjs-crawler
Try for free

No credit card required

Replacement for the legacy Apify Crawler product with a backward-compatible interface. The actor uses PhantomJS headless browser to recursively crawl websites and extract data from them using a piece of front-end JavaScript code.

Do you want to learn more about this Actor?

Get a demo

You can access the Legacy PhantomJS Crawler programmatically from your own JavaScript applications by using the Apify API. You can also choose the language preference from below. To use the Apify API, you’ll need an Apify account and your API token, found in Integrations settings in Apify Console.

1import { ApifyClient } from 'apify-client';
2
3// Initialize the ApifyClient with your Apify API token
4// Replace the '<YOUR_API_TOKEN>' with your token
5const client = new ApifyClient({
6    token: '<YOUR_API_TOKEN>',
7});
8
9// Prepare Actor input
10const input = {
11    "startUrls": [
12        {
13            "key": "START",
14            "value": "https://www.example.com/"
15        }
16    ],
17    "crawlPurls": [
18        {
19            "key": "MY_LABEL",
20            "value": "https://www.example.com/[.*]"
21        }
22    ],
23    "clickableElementsSelector": "a:not([rel=nofollow])",
24    "pageFunction": function pageFunction(context) {
25        // called on every page the crawler visits, use it to extract data from it
26        var $ = context.jQuery;
27        var result = {
28            title: $('title').text(),
29            myValue: $('TODO').text()
30        };
31        return result;
32    },
33    "interceptRequest": function interceptRequest(context, newRequest) {
34        // called whenever the crawler finds a link to a new page,
35        // use it to override default behavior
36        return newRequest;
37    }
38};
39
40// Run the Actor and wait for it to finish
41const run = await client.actor("apify/legacy-phantomjs-crawler").call(input);
42
43// Fetch and print Actor results from the run's dataset (if any)
44console.log('Results from dataset');
45console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
46const { items } = await client.dataset(run.defaultDatasetId).listItems();
47items.forEach((item) => {
48    console.dir(item);
49});
50
51// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

Legacy PhantomJS Crawler - Crawl websites, extract data API in JavaScript

The Apify API client for JavaScript is the official library that allows you to use Legacy PhantomJS Crawler API in JavaScript or TypeScript, providing convenience functions and automatic retries on errors.

Install the apify-client

npm install apify-client

Other API clients include:

Developer
Maintained by Apify

Actor Metrics

  • 101 monthly users

  • 21 stars

  • >99% runs succeeded

  • 7.8 days response time

  • Created in Mar 2019

  • Modified 6 months ago

Categories