1from apify_client import ApifyClient
2
3
4
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7
8run_input = {
9 "urls": [
10 "https://books.toscrape.com/",
11 "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
12 ],
13 "fields": [
14 {
15 "name": "title",
16 "instruction": "The main page or product title (full text, not truncated).",
17 "type": "text",
18 },
19 {
20 "name": "description",
21 "instruction": "The unique product or page description, written once, without a trailing '...more'. Null if none is given.",
22 "type": "text",
23 },
24 {
25 "name": "price",
26 "instruction": "Product price including the currency symbol as shown on the page. Null if this is not a product page.",
27 "type": "text",
28 },
29 {
30 "name": "category",
31 "instruction": "Product category or section name, if shown.",
32 "type": "text",
33 },
34 {
35 "name": "rating",
36 "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.",
37 "type": "number",
38 },
39 {
40 "name": "in_stock",
41 "instruction": "True if the product is in stock, false if out of stock, null if this is not a product page.",
42 "type": "boolean",
43 },
44 {
45 "name": "stock_count",
46 "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.",
47 "type": "number",
48 },
49 {
50 "name": "listed_items",
51 "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.",
52 "type": "list",
53 },
54 ],
55}
56
57
58run = client.actor("datatools-ai/ai-web-data-extractor").call(run_input=run_input)
59
60
61print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
62for item in client.dataset(run.default_dataset_id).iterate_items():
63 print(item)
64
65