1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "startUrls": [
12 {
13 "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
14 },
15 {
16 "url": "https://books.toscrape.com/catalogue/tipping-the-velvet_999/index.html"
17 }
18 ],
19 "instruction": "Extract the book details. Price as a number in GBP.",
20 "fields": [
21 "title",
22 "price (number)",
23 "currency",
24 "inStock (boolean)",
25 "availableCount (integer): copies in stock",
26 "description"
27 ],
28 "maxPages": 2
29};
30
31
32const run = await client.actor("gazidev/ai-web-data-extractor").call(input);
33
34
35console.log('Results from dataset');
36console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
37const { items } = await client.dataset(run.defaultDatasetId).listItems();
38items.forEach((item) => {
39 console.dir(item);
40});
41
42