Skip to content

Commit cf2f28f

Browse files
committed
docs: added an example of the smartScraper functionality using a schema
1 parent ee5738b commit cf2f28f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

scrapegraph-js/readme.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,34 @@ const prompt = 'Extract the main heading and description.';
7777
```
7878

7979
#### 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:
8084

8185
```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+
})();
83108
```
84109

85110
### Checking API Credits

0 commit comments

Comments
 (0)