File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -77,9 +77,34 @@ const prompt = 'Extract the main heading and description.';
77
77
```
78
78
79
79
#### Scraping with Custom Output Schema
80
+ > [ !NOTE]
81
+ > To use this feature, it is necessary to employ the [ Zod] ( https://www.npmjs.com/package/zod ) package for schema creation.
82
+
83
+ Here is a real-world example:
80
84
81
85
``` javascript
82
- // TODO
86
+ import { smartScraper } from ' scrapegraph-js' ;
87
+ import { z } from ' zod' ;
88
+ import ' dotenv/config' ;
89
+
90
+ const apiKey = ' your-api-key' ;
91
+ const url = ' https://scrapegraphai.com/' ;
92
+ const prompt = ' What does the company do? and ' ;
93
+
94
+ const schema = z .object ({
95
+ title: z .string ().describe (' The title of the webpage' ),
96
+ description: z .string ().describe (' The description of the webpage' ),
97
+ summary: z .string ().describe (' A brief summary of the webpage' )
98
+ });
99
+
100
+ (async () => {
101
+ try {
102
+ const response = await smartScraper (apiKey, url, prompt, schema);
103
+ console .log (response .result );
104
+ } catch (error) {
105
+ console .error (' Error:' , error);
106
+ }
107
+ })();
83
108
```
84
109
85
110
### Checking API Credits
You can’t perform that action at this time.
0 commit comments