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.

The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn more

1# Set API token
2API_TOKEN=<YOUR_API_TOKEN>
3
4# Prepare Actor input
5cat > input.json <<'EOF'
6{
7  "requests": [
8    {
9      "url": "https://apify.com"
10    }
11  ],
12  "pseudoUrls": [
13    {
14      "purl": "https://apify.com[(/[\\w-]+)?]"
15    }
16  ],
17  "linkSelector": "a[href]",
18  "pageFunction": "async function pageFunction(context) {\n    const { window, document, crawler, enqueueRequest, request, response, userData, json, body, kvStore, customData } = context;\n\n    const title = document.querySelector('title').textContent\n\n    const responseHeaders = response.headers\n\n    return {\n        title,\n        responseHeaders\n    };\n}",
19  "preNavigationHooks": "// We need to return array of (possibly async) functions here.\n// The functions accept two arguments: the \"crawlingContext\" object\n// and \"requestAsBrowserOptions\" which are passed to the `requestAsBrowser()`\n// function the crawler calls to navigate..\n[\n    async (crawlingContext, requestAsBrowserOptions) => {\n        // ...\n    }\n]",
20  "postNavigationHooks": "// We need to return array of (possibly async) functions here.\n// The functions accept a single argument: the \"crawlingContext\" object.\n[\n    async (crawlingContext) => {\n        // ...\n    },\n]",
21  "proxy": {
22    "useApifyProxy": true
23  },
24  "additionalMimeTypes": [],
25  "customData": {}
26}
27EOF
28
29# Run the Actor using an HTTP API
30# See the full API reference at https://docs.apify.com/api/v2
31curl "https://api.apify.com/v2/acts/mstephen190~vanilla-js-scraper/runs?token=$API_TOKEN" \
32  -X POST \
33  -d @input.json \
34  -H 'Content-Type: application/json'
Developer
Maintained by Community
Actor metrics
  • 11 monthly users
  • 2 stars
  • 99.5% runs succeeded
  • Created in Mar 2022
  • Modified 10 months ago