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/catalogue/a-light-in-the-attic_1000/index.html"
13 ],
14 "schema": {
15 "type": "object",
16 "properties": {
17 "title": {
18 "type": "string",
19 "description": "Book title"
20 },
21 "price": {
22 "type": [
23 "number",
24 "null"
25 ],
26 "description": "Price as a number, without currency symbol"
27 },
28 "currency": {
29 "type": [
30 "string",
31 "null"
32 ],
33 "description": "ISO currency code or symbol"
34 },
35 "in_stock": {
36 "type": [
37 "boolean",
38 "null"
39 ],
40 "description": "True if the book is in stock"
41 },
42 "rating_stars": {
43 "type": [
44 "integer",
45 "null"
46 ],
47 "minimum": 1,
48 "maximum": 5
49 }
50 },
51 "required": [
52 "title",
53 "price"
54 ],
55 "additionalProperties": false
56 },
57 "instructions": "",
58 "maxItems": 5,
59 "proxyConfiguration": {
60 "useApifyProxy": true
61 }
62};
63
64
65const run = await client.actor("tiger19935/schema-ai-extractor").call(input);
66
67
68console.log('Results from dataset');
69console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
70const { items } = await client.dataset(run.defaultDatasetId).listItems();
71items.forEach((item) => {
72 console.dir(item);
73});
74
75