Skip to content

Commit 83c25ed

Browse files
authored
Merge pull request #48 from ScrapeGraphAI/docs/v2-sdk-snippets-refresh
docs(v2): refresh snippets to match scrapegraph-py 2.x and scrapegrap…
2 parents 100b9c9 + 8b2b0bb commit 83c25ed

8 files changed

Lines changed: 1040 additions & 776 deletions

File tree

sdks/javascript.mdx

Lines changed: 173 additions & 221 deletions
Large diffs are not rendered by default.

sdks/python.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ApiResult(BaseModel, Generic[T]):
7474
| Variable | Description | Default |
7575
| --------------- | -------------------------------------------- | --------------------------------------- |
7676
| `SGAI_API_KEY` | Your ScrapeGraphAI API key ||
77-
| `SGAI_API_URL` | Override API base URL | `https://api.scrapegraphai.com/api/v2` |
77+
| `SGAI_API_URL` | Override API base URL | `https://v2-api.scrapegraphai.com/api` |
7878
| `SGAI_TIMEOUT` | Request timeout in seconds | `120` |
7979
| `SGAI_DEBUG` | Enable debug logging (set to `"1"`) | off |
8080

services/crawl.mdx

Lines changed: 147 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ icon: 'spider'
66

77
## Overview
88

9-
Crawl is an advanced web crawling service that traverses multiple pages, follows links, and returns content in your preferred format (markdown or HTML). It provides namespaced operations for starting, monitoring, stopping, and resuming crawl jobs.
9+
Crawl traverses a site starting from a URL, follows links up to a depth you set, and returns each page in the formats you request. Crawls are async — you start a job, then poll (or get notified via webhook) until it completes.
1010

1111
<Note>
12-
Try Crawl instantly in our [interactive playground](https://scrapegraphai.com/dashboard)
12+
Try Crawl instantly in our [interactive playground](https://scrapegraphai.com/dashboard).
1313
</Note>
1414

1515
## Getting Started
@@ -19,53 +19,83 @@ Try Crawl instantly in our [interactive playground](https://scrapegraphai.com/da
1919
<CodeGroup>
2020

2121
```python Python
22-
from scrapegraph_py import Client
23-
24-
client = Client(api_key="your-api-key")
25-
26-
# Start a crawl
27-
response = client.crawl.start(
28-
"https://example.com",
29-
depth=2,
30-
max_pages=10,
31-
format="markdown",
32-
)
33-
print("Crawl started:", response)
22+
import time
23+
from scrapegraph_py import ScrapeGraphAI, CrawlRequest, MarkdownFormatConfig
24+
25+
# reads SGAI_API_KEY from env, or pass explicitly: ScrapeGraphAI(api_key="...")
26+
sgai = ScrapeGraphAI()
27+
28+
start = sgai.crawl.start(CrawlRequest(
29+
url="https://scrapegraphai.com/",
30+
formats=[MarkdownFormatConfig()],
31+
max_pages=5,
32+
max_depth=2,
33+
))
34+
35+
if start.status != "success":
36+
print("Failed:", start.error)
37+
else:
38+
crawl_id = start.data.id
39+
print("Crawl started:", crawl_id)
40+
41+
while True:
42+
time.sleep(2)
43+
status = sgai.crawl.get(crawl_id)
44+
if status.status != "success":
45+
break
46+
print(f"{status.data.finished}/{status.data.total} - {status.data.status}")
47+
if status.data.status in ("completed", "failed"):
48+
for page in status.data.pages:
49+
print(f" {page.url} - {page.status}")
50+
break
3451
```
3552

3653
```javascript JavaScript
37-
import { crawl } from 'scrapegraph-js';
54+
import { ScrapeGraphAI } from "scrapegraph-js";
55+
56+
const sgai = ScrapeGraphAI();
3857

39-
const job = await crawl.start('your-api-key', {
40-
url: 'https://example.com',
58+
const start = await sgai.crawl.start({
59+
url: "https://scrapegraphai.com/",
60+
formats: [{ type: "markdown" }],
61+
maxPages: 5,
4162
maxDepth: 2,
42-
maxPages: 10,
43-
formats: [{ type: 'markdown' }],
4463
});
4564

46-
if (job.status === 'success') {
47-
console.log('Crawl started:', job.data?.id);
48-
49-
// Check status
50-
const status = await crawl.get('your-api-key', job.data?.id);
51-
52-
// Stop / Resume / Delete
53-
await crawl.stop('your-api-key', job.data?.id);
54-
await crawl.resume('your-api-key', job.data?.id);
55-
await crawl.delete('your-api-key', job.data?.id);
65+
if (start.status !== "success" || !start.data) {
66+
console.error("Failed:", start.error);
67+
} else {
68+
const crawlId = start.data.id;
69+
console.log("Crawl started:", crawlId);
70+
71+
while (true) {
72+
await new Promise((r) => setTimeout(r, 2000));
73+
const status = await sgai.crawl.get(crawlId);
74+
if (status.status !== "success" || !status.data) break;
75+
console.log(`${status.data.finished}/${status.data.total} - ${status.data.status}`);
76+
if (status.data.status === "completed" || status.data.status === "failed") {
77+
for (const p of status.data.pages) console.log(` ${p.url} - ${p.status}`);
78+
break;
79+
}
80+
}
5681
}
5782
```
5883

5984
```bash cURL
60-
curl -X POST https://api.scrapegraphai.com/api/v2/crawl \
85+
# Start a crawl
86+
curl -X POST https://v2-api.scrapegraphai.com/api/crawl \
87+
-H "SGAI-APIKEY: $SGAI_API_KEY" \
6188
-H "Content-Type: application/json" \
62-
-H "Authorization: Bearer your-api-key" \
6389
-d '{
64-
"url": "https://example.com",
65-
"depth": 2,
66-
"max_pages": 10,
67-
"format": "markdown"
90+
"url": "https://scrapegraphai.com/",
91+
"formats": [{ "type": "markdown" }],
92+
"maxPages": 5,
93+
"maxDepth": 2
6894
}'
95+
96+
# Check status (replace :id with the crawl id returned above)
97+
curl -X GET https://v2-api.scrapegraphai.com/api/crawl/:id \
98+
-H "SGAI-APIKEY: $SGAI_API_KEY"
6999
```
70100

71101
</CodeGroup>
@@ -74,80 +104,108 @@ curl -X POST https://api.scrapegraphai.com/api/v2/crawl \
74104

75105
| Parameter | Type | Required | Description |
76106
|-----------|------|----------|-------------|
77-
| url | string | Yes | The starting URL to crawl. |
78-
| depth | int | No | How many levels deep to follow links. |
79-
| max_pages | int | No | Maximum number of pages to crawl. |
80-
| format | string | No | Output format: `"markdown"` or `"html"`. Default: `"markdown"`. |
81-
| include_patterns | list | No | URL patterns to include (e.g., `["/blog/*"]`). |
82-
| exclude_patterns | list | No | URL patterns to exclude (e.g., `["/admin/*"]`). |
83-
| fetch_config | FetchConfig | No | Configuration for page fetching (headers, stealth, etc.). |
107+
| `url` | string | Yes | Starting URL to crawl. |
108+
| `formats` | array | No | Output formats per page (see [Scrape formats](/services/scrape#output-formats)). |
109+
| `maxPages` / `max_pages` | int | No | Maximum number of pages to crawl. |
110+
| `maxDepth` / `max_depth` | int | No | How many levels deep to follow links. |
111+
| `maxLinksPerPage` / `max_links_per_page` | int | No | Cap on links expanded per page. |
112+
| `includePatterns` / `include_patterns` | array | No | URL patterns to include (e.g. `["/blog/*"]`). |
113+
| `excludePatterns` / `exclude_patterns` | array | No | URL patterns to exclude (e.g. `["/admin/*"]`). |
114+
| `fetchConfig` / `fetch_config` | object | No | Fetch options (see [Scrape · FetchConfig](/services/scrape#fetchconfig)). |
84115

85116
<Note>
86-
Get your API key from the [dashboard](https://scrapegraphai.com/dashboard)
117+
Get your API key from the [dashboard](https://scrapegraphai.com/dashboard).
87118
</Note>
88119

89-
## Managing Crawl Jobs
90-
91-
### Check Status
92-
93-
```python
94-
status = client.crawl.status(crawl_id)
95-
print("Status:", status)
120+
<Accordion title="Example Response (start)" icon="terminal">
121+
```json
122+
{
123+
"id": "79694e03-f2ea-43f2-93cc-7c6fc26f999a",
124+
"status": "running",
125+
"total": 3,
126+
"finished": 0,
127+
"pages": []
128+
}
129+
```
130+
</Accordion>
131+
132+
<Accordion title="Example Response (get)" icon="terminal">
133+
```json
134+
{
135+
"id": "79694e03-f2ea-43f2-93cc-7c6fc26f999a",
136+
"status": "completed",
137+
"total": 3,
138+
"finished": 1,
139+
"pages": [
140+
{
141+
"url": "https://example.com",
142+
"depth": 0,
143+
"title": "",
144+
"status": "completed",
145+
"parentUrl": null,
146+
"contentType": "text/html",
147+
"links": ["https://iana.org/domains/example"],
148+
"scrapeRefId": "83a911ed-c0bc-4a8c-ad62-8efeeb93f33a"
149+
}
150+
]
151+
}
96152
```
153+
</Accordion>
97154

98-
### Stop a Running Crawl
155+
## Managing Crawl Jobs
99156

100157
```python
101-
client.crawl.stop(crawl_id)
102-
```
158+
# Check status
159+
status = sgai.crawl.get(crawl_id)
103160

104-
### Resume a Stopped Crawl
161+
# Stop / resume / delete
162+
sgai.crawl.stop(crawl_id)
163+
sgai.crawl.resume(crawl_id)
164+
sgai.crawl.delete(crawl_id)
165+
```
105166

106-
```python
107-
client.crawl.resume(crawl_id)
167+
```javascript
168+
await sgai.crawl.get(crawlId);
169+
await sgai.crawl.stop(crawlId);
170+
await sgai.crawl.resume(crawlId);
171+
await sgai.crawl.delete(crawlId);
108172
```
109173

110174
## Advanced Usage
111175

112-
### With FetchConfig
176+
### URL patterns and fetch config
113177

114178
```python
115-
from scrapegraph_py import Client, FetchConfig
179+
from scrapegraph_py import ScrapeGraphAI, CrawlRequest, MarkdownFormatConfig, FetchConfig
116180

117-
client = Client(api_key="your-api-key")
181+
sgai = ScrapeGraphAI()
118182

119-
response = client.crawl.start(
120-
"https://example.com",
121-
depth=2,
183+
res = sgai.crawl.start(CrawlRequest(
184+
url="https://example.com",
185+
formats=[MarkdownFormatConfig()],
186+
max_depth=2,
122187
max_pages=10,
123-
format="markdown",
124188
include_patterns=["/blog/*"],
125189
exclude_patterns=["/admin/*"],
126-
fetch_config=FetchConfig(
127-
mode="js",
128-
stealth=True,
129-
wait=1000,
130-
headers={"User-Agent": "MyBot"},
131-
),
132-
)
190+
fetch_config=FetchConfig(mode="js", stealth=True, wait=1000),
191+
))
133192
```
134193

135-
### Async Support
194+
### Async Support (Python)
136195

137196
```python
138197
import asyncio
139-
from scrapegraph_py import AsyncClient
198+
from scrapegraph_py import AsyncScrapeGraphAI, CrawlRequest
140199

141200
async def main():
142-
async with AsyncClient(api_key="your-api-key") as client:
143-
job = await client.crawl.start(
144-
"https://example.com",
145-
depth=2,
201+
async with AsyncScrapeGraphAI() as sgai:
202+
start = await sgai.crawl.start(CrawlRequest(
203+
url="https://example.com",
146204
max_pages=5,
147-
)
148-
149-
status = await client.crawl.status(job["id"])
150-
print("Crawl status:", status)
205+
max_depth=2,
206+
))
207+
status = await sgai.crawl.get(start.data.id)
208+
print("Status:", status.data.status)
151209

152210
asyncio.run(main())
153211
```
@@ -156,34 +214,34 @@ asyncio.run(main())
156214

157215
<CardGroup cols={2}>
158216
<Card title="Multi-Page Crawling" icon="sitemap">
159-
Traverse entire websites following links automatically
217+
Traverse entire sites, following links automatically.
160218
</Card>
161219
<Card title="Flexible Formats" icon="file-lines">
162-
Get results in markdown or HTML format
220+
Request markdown, HTML, links, images, and more per page.
163221
</Card>
164222
<Card title="Job Control" icon="sliders">
165-
Start, stop, resume, and monitor crawl jobs
223+
Start, stop, resume, and delete crawl jobs.
166224
</Card>
167225
<Card title="URL Filtering" icon="filter">
168-
Include or exclude pages by URL patterns
226+
Include or exclude by URL pattern.
169227
</Card>
170228
</CardGroup>
171229

172230
## Integration Options
173231

174232
### Official SDKs
175-
- [Python SDK](/sdks/python) - Perfect for data science and backend applications
176-
- [JavaScript SDK](/sdks/javascript) - Ideal for web applications and Node.js
233+
- [Python SDK](/sdks/python)
234+
- [JavaScript SDK](/sdks/javascript) (`scrapegraph-js` ≥ 2.0.1, Node ≥ 22)
177235

178236
### AI Framework Integrations
179-
- [LangChain Integration](/integrations/langchain) - Use Crawl in your LLM workflows
180-
- [LlamaIndex Integration](/integrations/llamaindex) - Build powerful search and QA systems
237+
- [LangChain Integration](/integrations/langchain)
238+
- [LlamaIndex Integration](/integrations/llamaindex)
181239

182240
## Support & Resources
183241

184242
<CardGroup cols={2}>
185243
<Card title="Documentation" icon="book" href="/introduction">
186-
Comprehensive guides and tutorials
244+
Guides and tutorials
187245
</Card>
188246
<Card title="API Reference" icon="code" href="/api-reference/introduction">
189247
Detailed API documentation

0 commit comments

Comments
 (0)