Vanilla JS Scraper avatar

Vanilla JS Scraper

Try for free

No credit card required

View all Actors
Vanilla JS Scraper

Vanilla JS Scraper

mstephen190/vanilla-js-scraper
Try for free

No credit card required

Scrape the web using familiar JavaScript methods! Crawls websites using raw HTTP requests, parses the HTML with the JSDOM package, and extracts data from the pages using Node.js code. Supports both recursive crawling and lists of URLs. This actor is a non jQuery alternative to CheerioScraper.

You can access the Vanilla JS Scraper 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    "requests": [
12        {
13            "url": "https://apify.com"
14        }
15    ],
16    "pseudoUrls": [
17        {
18            "purl": "https://apify.com[(/[\\w-]+)?]"
19        }
20    ],
21    "linkSelector": "a[href]",
22    "pageFunction": async function pageFunction(context) {
23        const { window, document, crawler, enqueueRequest, request, response, userData, json, body, kvStore, customData } = context;
24    
25        const title = document.querySelector('title').textContent
26    
27        const responseHeaders = response.headers
28    
29        return {
30            title,
31            responseHeaders
32        };
33    },
34    "preNavigationHooks": `// We need to return array of (possibly async) functions here.
35        // The functions accept two arguments: the "crawlingContext" object
36        // and "requestAsBrowserOptions" which are passed to the `requestAsBrowser()`
37        // function the crawler calls to navigate..
38        [
39            async (crawlingContext, requestAsBrowserOptions) => {
40                // ...
41            }
42        ]`,
43    "postNavigationHooks": `// We need to return array of (possibly async) functions here.
44        // The functions accept a single argument: the "crawlingContext" object.
45        [
46            async (crawlingContext) => {
47                // ...
48            },
49        ]`,
50    "proxy": {
51        "useApifyProxy": true
52    },
53    "additionalMimeTypes": [],
54    "customData": {}
55};
56
57// Run the Actor and wait for it to finish
58const run = await client.actor("mstephen190/vanilla-js-scraper").call(input);
59
60// Fetch and print Actor results from the run's dataset (if any)
61console.log('Results from dataset');
62console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
63const { items } = await client.dataset(run.defaultDatasetId).listItems();
64items.forEach((item) => {
65    console.dir(item);
66});
67
68// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

Vanilla JS Scraper API in JavaScript

The Apify API client for JavaScript is the official library that allows you to use Vanilla JS Scraper 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 Community
Actor metrics
  • 11 monthly users
  • 3 stars
  • 99.3% runs succeeded
  • Created in Mar 2022
  • Modified about 1 year ago