Skip to content

Commit 3c2178e

Browse files
committed
fix: readme js sdk
1 parent 6752c43 commit 3c2178e

File tree

2 files changed

+147
-98
lines changed

2 files changed

+147
-98
lines changed

β€Žscrapegraph-js/readme.md

Lines changed: 144 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,200 @@
1-
# ScrapeGraph JS SDK
1+
# 🌐 ScrapeGraph JavaScript SDK
22

3-
A JavaScript SDK for interacting with the ScrapeGraph AI API. This SDK provides easy-to-use functions for web scraping, managing credits, and submitting feedback.
3+
[![npm version](https://badge.fury.io/js/scrapegraph-js.svg)](https://badge.fury.io/js/scrapegraph-js)
4+
[![TypeScript Support](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
5+
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6+
[![Build Status](https://github.com/ScrapeGraphAI/scrapegraph-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/ScrapeGraphAI/scrapegraph-sdk/actions)
7+
[![Documentation Status](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://docs.scrapegraphai.com)
48

5-
## Installation
9+
Official JavaScript/TypeScript SDK for the ScrapeGraph AI API - Smart web scraping powered by AI.
610

7-
Install the package using npm:
11+
## πŸš€ Features
812

9-
```bash
10-
npm install scrapegraph-js
11-
```
13+
- ✨ Smart web scraping with AI
14+
- πŸ”„ Fully asynchronous design
15+
- πŸ“Š TypeScript-ready with strongly typed responses
16+
- πŸ” Detailed error handling
17+
- ⚑ Automatic retries and logging
18+
- πŸ” Secure API authentication
1219

13-
## Usage
20+
## πŸ“¦ Installation
1421

15-
> [!WARNING]
16-
> Remember not to write API keys directly in the code; instead, store them securely in `.env` files.
22+
Install the package using npm or yarn:
1723

18-
First, import the required functions:
24+
```bash
25+
# Using npm
26+
npm install scrapegraph-js
1927

20-
```javascript
21-
import { smartScraper, getSmartScraperRequest, getCredits, sendFeedback } from 'scrapegraph-sdk';
22-
```
2328

24-
### Scraping Websites
29+
## πŸ”§ Quick Start
30+
31+
> **Note**: Store your API keys securely in environment variables. Use `.env` files and libraries like `dotenv` to load them into your app.
2532

26-
#### Basic scraping
33+
### Basic Example
2734

2835
```javascript
29-
import { smartScraper } from 'scrapegraph-sdk';
36+
import { smartScraper } from 'scrapegraph-js';
3037
31-
const apiKey = process.env.SGAI_APIKEY;
32-
const url = 'https://scrapegraphai.com';
38+
// Initialize variables
39+
const apiKey = process.env.SGAI_APIKEY; // Set your API key as an environment variable
40+
const websiteUrl = 'https://example.com';
3341
const prompt = 'What does the company do?';
3442
35-
try {
36-
const response = await smartScraper(apiKey, url, prompt);
37-
console.log(response);
38-
} catch (error) {
39-
console.error(error);
40-
}
43+
(async () => {
44+
try {
45+
const response = await smartScraper(apiKey, websiteUrl, prompt);
46+
console.log(response.result);
47+
} catch (error) {
48+
console.error('Error:', error);
49+
}
50+
})();
4151
```
4252
43-
#### Scraping with custom output schema
53+
## 🎯 Examples
54+
55+
### Scraping Websites
56+
57+
#### Basic Scraping
4458
4559
```javascript
46-
import { smartScraper } from 'scrapegraph-sdk';
60+
import { smartScraper } from 'scrapegraph-js';
61+
62+
const apiKey = 'your-api-key';
63+
const url = 'https://example.com';
64+
const prompt = 'Extract the main heading and description.';
65+
66+
(async () => {
67+
try {
68+
const response = await smartScraper(apiKey, url, prompt);
69+
console.log(response.result);
70+
} catch (error) {
71+
console.error('Error:', error);
72+
}
73+
})();
74+
```
4775
48-
const apiKey = 'your_api_key';
49-
const url = 'https://scrapegraphai.com';
50-
const prompt = 'What does the company do?';
51-
const schema = //TODO
76+
#### Scraping with Custom Output Schema
77+
78+
```typescript
79+
import { smartScraper } from 'scrapegraph-js';
5280
53-
try {
54-
const response = await smartScraper(apiKey, url, prompt, schema);
55-
console.log(response);
56-
} catch (error) {
57-
console.error(error);
81+
interface WebsiteData {
82+
title: string;
83+
description: string;
5884
}
85+
86+
const apiKey = 'your-api-key';
87+
const url = 'https://example.com';
88+
const prompt = 'Extract the title and description.';
89+
90+
(async () => {
91+
try {
92+
const response = await smartScraper<WebsiteData>(apiKey, url, prompt);
93+
console.log(response.result.title, response.result.description);
94+
} catch (error) {
95+
console.error('Error:', error);
96+
}
97+
})();
5998
```
6099
61-
### Checking Credits
100+
### Checking API Credits
62101
63102
```javascript
64-
import { getCredist } from 'scrapegraph-sdk';
65-
66-
const apiKey = 'your_api_key';
67-
68-
try {
69-
const myCredit = await getCredits(apiKey);
70-
console.log(myCredit)
71-
} catch (error) {
72-
console.error(error)
73-
}
103+
import { getCredits } from 'scrapegraph-js';
104+
105+
const apiKey = 'your-api-key';
106+
107+
(async () => {
108+
try {
109+
const credits = await getCredits(apiKey);
110+
console.log('Available credits:', credits);
111+
} catch (error) {
112+
console.error('Error fetching credits:', error);
113+
}
114+
})();
74115
```
75116
76117
### Submitting Feedback
77118
78119
```javascript
79-
import { sendFeedback } from 'scrapegraph-sdk';
120+
import { sendFeedback } from 'scrapegraph-js';
80121
81-
const apiKey = 'your_api_key';
122+
const apiKey = 'your-api-key';
82123
const requestId = '16a63a80-c87f-4cde-b005-e6c3ecda278b';
83124
const rating = 5;
84-
const feedbackMessage = 'This is a test feedback message.';
85-
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-
}
125+
const feedbackText = 'This is a test feedback message.';
126+
127+
(async () => {
128+
try {
129+
const response = await sendFeedback(apiKey, requestId, rating, feedbackText);
130+
console.log('Feedback response:', response);
131+
} catch (error) {
132+
console.error('Error sending feedback:', error);
133+
}
134+
})();
92135
```
93136
94-
## API Reference
95-
96-
### scrape(apiKey, url[, options])
137+
## πŸ“š Documentation
97138
98-
Scrapes a website and returns the extracted data.
139+
For detailed documentation, visit [docs.scrapegraphai.com](https://docs.scrapegraphai.com)
99140
100-
Parameters:
101-
- `apiKey` (string): Your ScrapeGraph AI API key
102-
- `url` (string): The URL to scrape
103-
- `options` (object, optional):
104-
- `elements` (array): Specific elements to extract
105-
- `wait_for` (string): CSS selector to wait for before scraping
106-
- `javascript` (boolean): Enable JavaScript rendering
141+
## πŸ› οΈ Development
107142
108-
### credits(apiKey)
143+
### Setup
109144
110-
Retrieves your current credit balance.
145+
1. Clone the repository:
146+
```bash
147+
git clone https://github.com/ScrapeGraphAI/scrapegraph-sdk.git
148+
cd scrapegraph-sdk/scrapegraph-js
149+
```
111150
112-
Parameters:
113-
- `apiKey` (string): Your ScrapeGraph AI API key
151+
2. Install dependencies:
152+
```bash
153+
npm install
154+
```
114155
115-
### feedback(apiKey, requestId, rating, feedbackText)
156+
3. Run linting and testing:
157+
```bash
158+
npm run lint
159+
npm test
160+
```
116161
117-
Submits feedback for a scraping request.
162+
### Running Tests
118163
119-
Parameters:
120-
- `apiKey` (string): Your ScrapeGraph AI API key
121-
- `requestId` (string): The request ID from the scrape response
122-
- `rating` (number): Rating score
123-
- `feedbackText` (string) (optional): Feedback message
164+
```bash
165+
# Run all tests
166+
npm test
124167
125-
## Error Handling
168+
# Run tests with coverage
169+
npm run test:coverage
170+
```
126171
127-
All functions return javascript `Error` object with imformation. In case of errors, the response will include error details:
172+
## πŸ“ License
128173
129-
// TODO error list
174+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
130175
131-
```javascript
132-
{
133-
"statusCode": 400,
134-
"title": "HTTP error occurred"
135-
"details": "Error details",
136-
137-
}
138-
```
176+
## 🀝 Contributing
139177
140-
## License
178+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
141179
142-
MIT
180+
1. Fork the repository
181+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
182+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
183+
4. Push to the branch (`git push origin feature/AmazingFeature`)
184+
5. Open a Pull Request
143185
144-
## Support
186+
## πŸ”— Links
145187
146-
For support, please visit [ScrapeGraph AI Documentation](https://sgai-api.onrender.com/docs).
188+
- [Website](https://scrapegraphai.com)
189+
- [Documentation](https://scrapegraphai.com/documentation)
190+
- [GitHub](https://github.com/ScrapeGraphAI/scrapegraph-sdk)
147191
192+
## πŸ’¬ Support
148193
194+
- πŸ“§ Email: [email protected]
195+
- πŸ’» GitHub Issues: [Create an issue](https://github.com/ScrapeGraphAI/scrapegraph-sdk/issues)
196+
- 🌟 Feature Requests: [Request a feature](https://github.com/ScrapeGraphAI/scrapegraph-sdk/issues/new)
149197
198+
---
150199
200+
Made with ❀️ by [ScrapeGraph AI](https://scrapegraphai.com)

β€Žscrapegraph-py/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ Contributions are welcome! Please feel free to submit a Pull Request. For major
155155

156156
## πŸ”— Links
157157

158-
- [Website](https://scrapegraphai.com)
159-
- [Documentation](https://docs.scrapegraphai.com)
160-
- [API Reference](https://docs.scrapegraphai.com/api)
161-
- [GitHub](https://github.com/ScrapeGraphAI/scrapegraph-sdk)
158+
- [Website](https://scrapegraphai.com)
159+
- [Documentation](https://scrapegraphai.com/documentation)
160+
- [GitHub](https://github.com/ScrapeGraphAI/scrapegraph-sdk)
162161

163162
## πŸ’¬ Support
164163

0 commit comments

Comments
Β (0)