Skip to content

Commit c9153e4

Browse files
fix: address code smells in examples and README
- Remove process.exit() from crawl example, use if/else instead - Fix non-null assertion in crawl example - Fix undefined variable references in README crawl section - Use consistent example.com URLs across all examples Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e30cc55 commit c9153e4

4 files changed

Lines changed: 15 additions & 16 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ const start = await crawl.start("key", {
144144
});
145145

146146
// Check status
147-
const status = await crawl.get("key", start.data.id);
147+
const status = await crawl.get("key", start.data?.id!);
148148

149-
// Control
150-
await crawl.stop("key", id);
151-
await crawl.resume("key", id);
152-
await crawl.delete("key", id);
149+
// Control crawl by ID
150+
await crawl.stop("key", start.data?.id!);
151+
await crawl.resume("key", start.data?.id!);
152+
await crawl.delete("key", start.data?.id!);
153153
```
154154

155155
### monitor

examples/crawl/crawl_basic.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ const startRes = await crawl.start(apiKey, {
88
maxDepth: 2,
99
});
1010

11-
if (startRes.status !== "success") {
11+
if (startRes.status !== "success" || !startRes.data) {
1212
console.error("Failed to start:", startRes.error);
13-
process.exit(1);
14-
}
15-
16-
console.log("Crawl started:", startRes.data?.id);
17-
console.log("Status:", startRes.data?.status);
13+
} else {
14+
console.log("Crawl started:", startRes.data.id);
15+
console.log("Status:", startRes.data.status);
1816

19-
const getRes = await crawl.get(apiKey, startRes.data!.id);
20-
console.log("\nProgress:", getRes.data?.finished, "/", getRes.data?.total);
21-
console.log("Pages:", getRes.data?.pages.map((p) => p.url));
17+
const getRes = await crawl.get(apiKey, startRes.data.id);
18+
console.log("\nProgress:", getRes.data?.finished, "/", getRes.data?.total);
19+
console.log("Pages:", getRes.data?.pages.map((p) => p.url));
20+
}

examples/scrape/scrape_json_extraction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { scrape } from "scrapegraph-js";
33
const apiKey = process.env.SGAI_API_KEY!;
44

55
const res = await scrape(apiKey, {
6-
url: "https://scrapegraphai.com",
6+
url: "https://example.com",
77
formats: [
88
{
99
type: "json",

examples/scrape/scrape_multi_format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { scrape } from "scrapegraph-js";
33
const apiKey = process.env.SGAI_API_KEY!;
44

55
const res = await scrape(apiKey, {
6-
url: "https://scrapegraphai.com",
6+
url: "https://example.com",
77
formats: [
88
{ type: "markdown", mode: "reader" },
99
{ type: "html", mode: "prune" },

0 commit comments

Comments
 (0)