@@ -18,49 +18,77 @@ npm install scrapegraph-js
1818First, import the required functions:
1919
2020``` javascript
21- import { scrape , credits , feedback } from ' scrapegraph-js ' ;
21+ import { smartScraper , getSmartScraperRequest , getCredits , sendFeedback } from ' scrapegraph-sdk ' ;
2222```
2323
2424### Scraping Websites
2525
26+ #### Basic scraping
27+
2628``` javascript
27- const apiKey = ' your_api_key' ;
28- const url = ' https://example.com' ;
29+ import { smartScraper } from ' scrapegraph-sdk' ;
2930
30- // Basic scraping
31- const result = await scrape (apiKey, url) ;
32- console . log ( JSON . parse (result)) ;
31+ const apiKey = process . env . SGAI_APIKEY ;
32+ const url = ' https://scrapegraphai.com ' ;
33+ const prompt = ' What does the company do? ' ;
3334
34- // Scraping with custom options
35- const options = {
36- elements: [' h1' , ' .product-price' ],
37- wait_for: ' .specific-element' ,
38- javascript: true
39- };
35+ try {
36+ const response = await smartScraper (apiKey, url, prompt);
37+ console .log (response);
38+ } catch (error) {
39+ console .error (error);
40+ }
41+ ```
42+
43+ #### Scraping with custom output schema
44+
45+ ``` javascript
46+ import { smartScraper } from ' scrapegraph-sdk' ;
4047
41- const customResult = await scrape (apiKey, url, options);
42- console .log (JSON .parse (customResult));
48+ const apiKey = ' your_api_key' ;
49+ const url = ' https://scrapegraphai.com' ;
50+ const prompt = ' What does the company do?' ;
51+ const schema = // TODO
52+
53+ try {
54+ const response = await smartScraper (apiKey, url, prompt, schema);
55+ console .log (response);
56+ } catch (error) {
57+ console .error (error);
58+ }
4359```
4460
4561### Checking Credits
4662
4763``` javascript
64+ import { getCredist } from ' scrapegraph-sdk' ;
65+
4866const apiKey = ' your_api_key' ;
4967
50- const creditsInfo = await credits (apiKey);
51- console .log (JSON .parse (creditsInfo));
68+ try {
69+ const myCredit = await getCredits (apiKey);
70+ console .log (myCredit)
71+ } catch (error) {
72+ console .error (error)
73+ }
5274```
5375
5476### Submitting Feedback
5577
5678``` javascript
79+ import { sendFeedback } from ' scrapegraph-sdk' ;
80+
5781const apiKey = ' your_api_key' ;
58- const requestId = ' request_id_from_scrape_response ' ;
82+ const requestId = ' 16a63a80-c87f-4cde-b005-e6c3ecda278b ' ;
5983const rating = 5 ;
60- const feedbackText = ' Great results! ' ;
84+ const feedbackMessage = ' This is a test feedback message. ' ;
6185
62- const feedbackResponse = await feedback (apiKey, requestId, rating, feedbackText);
63- console .log (JSON .parse (feedbackResponse));
86+ try {
87+ const feedback_response = await sendFeedback (apiKey, requestId, rating, feedbackMessage);
88+ console .log (feedback_response);
89+ } catch (error) {
90+ console .error (error)
91+ }
6492```
6593
6694## API Reference
@@ -92,17 +120,20 @@ Parameters:
92120- ` apiKey ` (string): Your ScrapeGraph AI API key
93121- ` requestId ` (string): The request ID from the scrape response
94122- ` rating ` (number): Rating score
95- - ` feedbackText ` (string): Feedback message
123+ - ` feedbackText ` (string) (optional) : Feedback message
96124
97125## Error Handling
98126
99- All functions return JSON strings that you should parse. In case of errors, the response will include error details:
127+ All functions return javascript ` Error ` object with imformation. In case of errors, the response will include error details:
128+
129+ // TODO error list
100130
101131``` javascript
102132{
103- " error" : " HTTP error occurred" ,
104- " message" : " Error details" ,
105- " status_code" : 400
133+ " statusCode" : 400 ,
134+ " title" : " HTTP error occurred"
135+ " details" : " Error details" ,
136+
106137}
107138```
108139
0 commit comments