Web Scraper new avatar
Web Scraper new

Under maintenance

Pricing

Pay per event

Go to Store
Web Scraper new

Web Scraper new

Under maintenance

Developed by

Jan Kirchner

Jan Kirchner

Maintained by Community

The scraper of Web

5.0 (1)

Pricing

Pay per event

1

Total users

3

Monthly users

3

Last modified

a month ago

You can access the Web Scraper new programmatically from your own 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 "url": "https://apify.com"
14 }
15 ],
16 "linkSelector": "a[href]",
17 "pseudoUrls": [
18 {
19 "purl": "https://apify.com[(/[\\w-]+)?]"
20 }
21 ],
22 "pageFunction": // The function accepts a single argument: the "context" object.
23 // For a complete list of its properties and functions,
24 // see https://apify.com/apify/web-scraper#page-function
25 async function pageFunction(context) {
26 // jQuery is handy for finding DOM elements and extracting data from them.
27 // To use it, make sure to enable the "Inject jQuery" option.
28 const $ = context.jQuery;
29 const pageTitle = $('title').first().text();
30
31 // Print some information to actor log
32 context.log.info(`URL: ${context.request.url}, TITLE: ${pageTitle}`);
33
34 // Manually add a new page to the queue for scraping.
35 // To make this work, make sure the "Use request queue" option is enabled.
36 context.enqueueRequest({ url: 'http://www.example.com' });
37
38 // Return an object with the data extracted from the page.
39 // It will be stored to the resulting dataset.
40 return {
41 url: context.request.url,
42 pageTitle
43 };
44 },
45 "proxyConfiguration": {
46 "useApifyProxy": false
47 },
48 "initialCookies": [],
49 "waitUntil": [
50 "networkidle2"
51 ],
52 "customData": {}
53};
54
55// Run the Actor and wait for it to finish
56const run = await client.actor("honzakirchner43/web-scraper-new").call(input);
57
58// Fetch and print Actor results from the run's dataset (if any)
59console.log('Results from dataset');
60console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
61const { items } = await client.dataset(run.defaultDatasetId).listItems();
62items.forEach((item) => {
63 console.dir(item);
64});
65
66// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

Web Scraper new API in JavaScript

The Apify API client for JavaScript is the official library that allows you to use Web Scraper new 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: