Skip to content

Commit 9d770a8

Browse files
committed
2 parents 81d8362 + 7593ed5 commit 9d770a8

15 files changed

+189
-60
lines changed

scrapegraph-js/CODE_OF_CONDUCT.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
1717
Examples of behavior that contributes to a positive environment for our
1818
community include:
1919

20-
* Demonstrating empathy and kindness toward other people
21-
* Being respectful of differing opinions, viewpoints, and experiences
22-
* Giving and gracefully accepting constructive feedback
23-
* Accepting responsibility and apologizing to those affected by our mistakes,
20+
- Demonstrating empathy and kindness toward other people
21+
- Being respectful of differing opinions, viewpoints, and experiences
22+
- Giving and gracefully accepting constructive feedback
23+
- Accepting responsibility and apologizing to those affected by our mistakes,
2424
and learning from the experience
25-
* Focusing on what is best not just for us as individuals, but for the
25+
- Focusing on what is best not just for us as individuals, but for the
2626
overall community
2727

2828
Examples of unacceptable behavior include:
2929

30-
* The use of sexualized language or imagery, and sexual attention or
30+
- The use of sexualized language or imagery, and sexual attention or
3131
advances of any kind
32-
* Trolling, insulting or derogatory comments, and personal or political attacks
33-
* Public or private harassment
34-
* Publishing others' private information, such as a physical or email
32+
- Trolling, insulting or derogatory comments, and personal or political attacks
33+
- Public or private harassment
34+
- Publishing others' private information, such as a physical or email
3535
address, without their explicit permission
36-
* Other conduct which could reasonably be considered inappropriate in a
36+
- Other conduct which could reasonably be considered inappropriate in a
3737
professional setting
3838

3939
## Enforcement Responsibilities
@@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
106106
### 4. Permanent Ban
107107

108108
**Community Impact**: Demonstrating a pattern of violation of community
109-
standards, including sustained inappropriate behavior, harassment of an
109+
standards, including sustained inappropriate behavior, harassment of an
110110
individual, or aggression toward or disparagement of classes of individuals.
111111

112112
**Consequence**: A permanent ban from any sort of public interaction within

scrapegraph-js/README.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Official JavaScript/TypeScript SDK for the ScrapeGraph AI API - Smart web scrapi
99

1010
## 🚀 Features
1111

12-
- ✨ Smart web scraping with AI
13-
- 🔄 Fully asynchronous design
14-
- 🔍 Detailed error handling
15-
- ⚡ Automatic retries and logging
16-
- 🔐 Secure API authentication
12+
- ✨ Smart web scraping with AI
13+
- 🔄 Fully asynchronous design
14+
- 🔍 Detailed error handling
15+
- ⚡ Automatic retries and logging
16+
- 🔐 Secure API authentication
1717

1818
## 📦 Installation
1919

@@ -23,11 +23,10 @@ Install the package using npm or yarn:
2323
# Using npm
2424
npm i scrapegraph-js
2525

26-
# Using yarn
26+
# Using yarn
2727
yarn add scrapegraph-js
2828
```
2929

30-
3130
## 🔧 Quick Start
3231

3332
> **Note**: Store your API keys securely in environment variables. Use `.env` files and libraries like `dotenv` to load them into your app.
@@ -36,7 +35,6 @@ yarn add scrapegraph-js
3635

3736
```javascript
3837
import { smartScraper } from 'scrapegraph-js';
39-
import 'dotenv/config';
4038

4139
// Initialize variables
4240
const apiKey = process.env.SGAI_APIKEY; // Set your API key as an environment variable
@@ -77,6 +75,7 @@ const prompt = 'Extract the main heading and description.';
7775
```
7876

7977
#### Scraping with Custom Output Schema
78+
8079
> [!NOTE]
8180
> To use this feature, it is necessary to employ the [Zod](https://www.npmjs.com/package/zod) package for schema creation.
8281
@@ -85,7 +84,6 @@ Here is a real-world example:
8584
```javascript
8685
import { smartScraper } from 'scrapegraph-js';
8786
import { z } from 'zod';
88-
import 'dotenv/config';
8987

9088
const apiKey = 'your-api-key';
9189
const url = 'https://scrapegraphai.com/';
@@ -94,7 +92,7 @@ const prompt = 'What does the company do? and ';
9492
const schema = z.object({
9593
title: z.string().describe('The title of the webpage'),
9694
description: z.string().describe('The description of the webpage'),
97-
summary: z.string().describe('A brief summary of the webpage')
95+
summary: z.string().describe('A brief summary of the webpage'),
9896
});
9997

10098
(async () => {
@@ -107,6 +105,25 @@ const schema = z.object({
107105
})();
108106
```
109107

108+
### Markdownify
109+
Converts a webpage into clean, well-structured markdown format.
110+
```javascript
111+
import { smartScraper } from 'scrapegraph-js';
112+
113+
const apiKey = "your_api_key";
114+
const url = 'https://scrapegraphai.com/';
115+
116+
(async () => {
117+
try {
118+
const response = await markdownify(apiKey, url);
119+
console.log(response);
120+
} catch (error) {
121+
console.error(error);
122+
}
123+
})();
124+
```
125+
126+
110127
### Checking API Credits
111128

112129
```javascript
@@ -153,12 +170,14 @@ For detailed documentation, visit [docs.scrapegraphai.com](https://docs.scrapegr
153170
### Setup
154171

155172
1. Clone the repository:
173+
156174
```bash
157175
git clone https://github.com/ScrapeGraphAI/scrapegraph-sdk.git
158176
cd scrapegraph-sdk/scrapegraph-js
159177
```
160178

161179
2. Install dependencies:
180+
162181
```bash
163182
npm install
164183
```
@@ -187,22 +206,22 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
187206

188207
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.
189208

190-
1. Fork the repository
191-
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
192-
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
193-
4. Push to the branch (`git push origin feature/AmazingFeature`)
194-
5. Open a Pull Request
209+
1. Fork the repository
210+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
211+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
212+
4. Push to the branch (`git push origin feature/AmazingFeature`)
213+
5. Open a Pull Request
195214

196215
## 🔗 Links
197216

198-
- [Website](https://scrapegraphai.com)
199-
- [Documentation](https://scrapegraphai.com/documentation)
200-
- [GitHub](https://github.com/ScrapeGraphAI/scrapegraph-sdk)
217+
- [Website](https://scrapegraphai.com)
218+
- [Documentation](https://scrapegraphai.com/documentation)
219+
- [GitHub](https://github.com/ScrapeGraphAI/scrapegraph-sdk)
201220

202221
## 💬 Support
203222

204-
- 📧 Email: [email protected]
205-
- 💻 GitHub Issues: [Create an issue](https://github.com/ScrapeGraphAI/scrapegraph-sdk/issues)
223+
- 📧 Email: [email protected]
224+
- 💻 GitHub Issues: [Create an issue](https://github.com/ScrapeGraphAI/scrapegraph-sdk/issues)
206225
- 🌟 Feature Requests: [Request a feature](https://github.com/ScrapeGraphAI/scrapegraph-sdk/issues/new)
207226

208227
---

scrapegraph-js/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export default [
77
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
88
pluginJs.configs.recommended,
99
eslintPluginPrettierRecommended,
10-
{ ignorePatterns: ['node_modules/'] },
10+
{ ignores: ['node_modules/'] },
1111
];

scrapegraph-js/examples/getCredits_example.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import 'dotenv/config';
44
const apiKey = process.env.SGAI_APIKEY;
55

66
try {
7-
const myCredit = await getCredits(apiKey);
8-
console.log(myCredit)
7+
const myCredit = await getCredits(apiKey);
8+
console.log(myCredit);
99
} catch (error) {
10-
console.error(error)
11-
}
10+
console.error(error);
11+
}

scrapegraph-js/examples/getSmartScraperRequest_example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { getSmartScraperRequest } from 'scrapegraph-js';
22
import 'dotenv/config';
33

44
const apiKey = process.env.SGAI_APIKEY;
5-
const requestId = '3fa85f64-5717-4562-b3fc-2c963f66afa6'
5+
const requestId = '3fa85f64-5717-4562-b3fc-2c963f66afa6';
66

77
try {
88
const requestInfo = await getSmartScraperRequest(apiKey, requestId);
99
console.log(requestInfo);
1010
} catch (error) {
1111
console.error(error);
12-
}
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { getMarkdownifyRequest, markdownify } from 'scrapegraph-js';
2+
import fs from 'fs';
3+
import 'dotenv/config';
4+
5+
// markdownify function example
6+
const apiKey = process.env.SGAI_APIKEY;
7+
const url = 'https://scrapegraphai.com/';
8+
9+
try {
10+
const response = await markdownify(apiKey, url);
11+
console.log(response);
12+
saveFile(response.result);
13+
} catch (error) {
14+
console.error(error);
15+
}
16+
17+
// helper function for save the file locally
18+
function saveFile(output) {
19+
try {
20+
fs.writeFileSync('result.md', output);
21+
console.log('Success!');
22+
} catch (err) {
23+
console.error('Error during the file writing: ', err);
24+
}
25+
}
26+
27+
// getMarkdownifyRequest function example
28+
const requestId = '2563b972-cb6f-400b-be76-edb235458560';
29+
30+
try {
31+
const response = await getMarkdownifyRequest(apiKey, requestId);
32+
console.log(response);
33+
} catch (error) {
34+
console.log(error);
35+
}

scrapegraph-js/examples/schema_smartScraper_example.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ const apiKey = process.env.SGAI_APIKEY;
66
const url = 'https://scrapegraphai.com/';
77
const prompt = 'What does the company do? and ';
88

9-
const schema = 2;
9+
const schema = z.object({
10+
title: z.string().describe('The title of the webpage'),
11+
description: z.string().describe('The description of the webpage'),
12+
summary: z.string().describe('A brief summary of the webpage'),
13+
});
1014

1115
try {
1216
const response = await smartScraper(apiKey, url, prompt, schema);
1317
console.log(response.result);
1418
} catch (error) {
1519
console.error(error);
16-
}
20+
}

scrapegraph-js/examples/sendFeedback_example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ try {
1010
const feedback_response = await sendFeedback(apiKey, requestId, rating, feedbackMessage);
1111
console.log(feedback_response);
1212
} catch (error) {
13-
console.error(error)
14-
}
13+
console.error(error);
14+
}

scrapegraph-js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { smartScraper, getSmartScraperRequest } from './src/smartScraper.js';
2+
export { markdownify, getMarkdownifyRequest } from './src/markdownify.js';
23
export { getCredits } from './src/credits.js';
3-
export { sendFeedback } from './src/feedback.js';
4+
export { sendFeedback } from './src/feedback.js';

scrapegraph-js/src/credits.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import handleError from './utils/handleError.js';
33

44
/**
55
* Retrieve credits from the API.
6-
*
6+
*
77
* @param {string} apiKey - Your ScrapeGraph AI API key
88
* @returns {Promise<string>} Response from the API in JSON format
99
*/
1010
export async function getCredits(apiKey) {
1111
const endpoint = 'https://api.scrapegraphai.com/v1/credits';
1212
const headers = {
1313
'accept': 'application/json',
14-
'SGAI-APIKEY': apiKey
14+
'SGAI-APIKEY': apiKey,
1515
};
1616

1717
try {
1818
const response = await axios.get(endpoint, { headers });
1919
return response.data;
2020
} catch (error) {
21-
handleError(error)
21+
handleError(error);
2222
}
23-
}
23+
}

scrapegraph-js/src/feedback.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import handleError from './utils/handleError.js';
33

44
/**
55
* Send feedback to the API.
6-
*
6+
*
77
* @param {string} apiKey - Your ScrapeGraph AI API key
88
* @param {string} requestId - The request ID associated with the feedback
99
* @param {number} rating - The rating score
@@ -15,13 +15,13 @@ export async function sendFeedback(apiKey, requestId, rating, feedbackText = nul
1515
const headers = {
1616
'accept': 'application/json',
1717
'SGAI-APIKEY': apiKey,
18-
'Content-Type': 'application/json'
18+
'Content-Type': 'application/json',
1919
};
2020

2121
const feedbackData = {
2222
request_id: requestId,
2323
rating: rating,
24-
feedback_text: feedbackText
24+
feedback_text: feedbackText,
2525
};
2626

2727
try {
@@ -30,4 +30,4 @@ export async function sendFeedback(apiKey, requestId, rating, feedbackText = nul
3030
} catch (error) {
3131
handleError(error);
3232
}
33-
}
33+
}

scrapegraph-js/src/markdownify.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import axios from 'axios';
2+
import handleError from './utils/handleError.js';
3+
4+
/**
5+
* Converts a webpage into clean, well-structured markdown format.
6+
*
7+
* @param {string} apiKey - Your ScrapeGraph AI API key.
8+
* @param {string} url - The URL of the webpage to be converted.
9+
* @returns {Promise<string>} A promise that resolves to the markdown representation of the webpage.
10+
* @throws {Error} Throws an error if the HTTP request fails.
11+
*/
12+
export async function markdownify(apiKey, url){
13+
const endpoint = 'https://api.scrapegraphai.com/v1/markdownify';
14+
const headers = {
15+
'accept': 'application/json',
16+
'SGAI-APIKEY': apiKey,
17+
};
18+
19+
const payload = {
20+
website_url: url,
21+
};
22+
23+
try {
24+
const response = await axios.post(endpoint, payload, { headers });
25+
return response.data;
26+
} catch (error) {
27+
handleError(error)
28+
}
29+
}
30+
31+
/**
32+
* Retrieves the status or result of a markdownify request, with the option to review results from previous requests.
33+
*
34+
* @param {string} apiKey - Your ScrapeGraph AI API key.
35+
* @param {string} requestId - The unique identifier for the markdownify request whose result you want to retrieve.
36+
* @returns {Promise<string>} A promise that resolves with details about the status or outcome of the specified request.
37+
* @throws {Error} Throws an error if the HTTP request fails.
38+
*/
39+
export async function getMarkdownifyRequest(apiKey, requestId){
40+
const endpoint = 'https://api.scrapegraphai.com/v1/markdownify/' + requestId;
41+
const headers = {
42+
'accept': 'application/json',
43+
'SGAI-APIKEY': apiKey,
44+
};
45+
46+
try {
47+
const response = await axios.get(endpoint, { headers });
48+
return response.data;
49+
} catch (error) {
50+
handleError(error)
51+
}
52+
}

0 commit comments

Comments
 (0)