1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "requests": [
12 {
13 "url": "https://www.scrapethissite.com/pages/simple/"
14 },
15 {
16 "id": "forms",
17 "url": "https://www.scrapethissite.com/pages/simple/",
18 "extract": [
19 {
20 "field_name": "extracted_html",
21 "selector": "#countries > div > div:nth-child(4) > div:nth-child(1)",
22 "extract_type": "HTML"
23 }
24 ]
25 },
26 {
27 "id": "hockey",
28 "url": "https://www.scrapethissite.com/pages/forms/",
29 "extract": [
30 {
31 "field_name": "year1",
32 "selector": "#hockey > div > table > tbody > tr:nth-child(2) > td.year",
33 "extract_type": "Text"
34 },
35 {
36 "field_name": "year2",
37 "selector": "#hockey > div > table > tbody > tr:nth-child(3) > td.year",
38 "extract_type": "Text"
39 },
40 {
41 "field_name": "class_name",
42 "selector": "#hockey > div > table > tbody > tr:nth-child(2) > td.year",
43 "extract_type": {
44 "Attribute": "class"
45 }
46 }
47 ]
48 }
49 ],
50 "proxy_settings": {
51 "useApifyProxy": true
52 }
53};
54
55
56const run = await client.actor("danielherman/fast-scraper").call(input);
57
58
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