1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "urls": [
12 "https://books.toscrape.com/",
13 "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
14 ],
15 "fields": [
16 {
17 "name": "title",
18 "instruction": "The main page or product title (full text, not truncated).",
19 "type": "text"
20 },
21 {
22 "name": "description",
23 "instruction": "The unique product or page description, written once, without a trailing '...more'. Null if none is given.",
24 "type": "text"
25 },
26 {
27 "name": "price",
28 "instruction": "Product price including the currency symbol as shown on the page. Null if this is not a product page.",
29 "type": "text"
30 },
31 {
32 "name": "category",
33 "instruction": "Product category or section name, if shown.",
34 "type": "text"
35 },
36 {
37 "name": "rating",
38 "instruction": "Star rating as a number from 1 to 5 if shown (for example 'star rating: 3/5' means 3). Null if this is not a product page or no rating is shown.",
39 "type": "number"
40 },
41 {
42 "name": "in_stock",
43 "instruction": "True if the product is in stock, false if out of stock, null if this is not a product page.",
44 "type": "boolean"
45 },
46 {
47 "name": "stock_count",
48 "instruction": "The number of items available in stock if a count is shown (for example 'In stock (22 available)' means 22). Null if not shown or not a product page.",
49 "type": "number"
50 },
51 {
52 "name": "listed_items",
53 "instruction": "Up to 8 full product titles from a catalog or listing page. Use the complete title (for example from each product link's title attribute), never a truncated label that ends with an ellipsis. Empty list if this is a single product page.",
54 "type": "list"
55 }
56 ]
57};
58
59
60const run = await client.actor("datatools-ai/ai-web-data-extractor").call(input);
61
62
63console.log('Results from dataset');
64console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
65const { items } = await client.dataset(run.defaultDatasetId).listItems();
66items.forEach((item) => {
67 console.dir(item);
68});
69
70