-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathall-formats.ts
More file actions
50 lines (39 loc) · 1.29 KB
/
all-formats.ts
File metadata and controls
50 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
/**
* All Formats Example
*
* Demonstrates outputting content in all supported formats (markdown and html)
*/
import { ReaderClient } from "@vakra-dev/reader";
async function main() {
console.log("Starting all-formats example\n");
const reader = new ReaderClient({ verbose: true });
try {
const result = await reader.scrape({
urls: ["https://example.com"],
formats: ["markdown", "html"],
});
const page = result.data[0];
if (!page) {
console.error("No data returned - scrape may have failed");
console.log("Errors:", result.batchMetadata.errors);
process.exit(1);
}
console.log("\nScrape completed!");
console.log("\nFormat Lengths:");
console.log(` Markdown: ${page.markdown?.length || 0} chars`);
console.log(` HTML: ${page.html?.length || 0} chars`);
console.log("\n--- MARKDOWN OUTPUT ---");
console.log(page.markdown?.slice(0, 500));
console.log("\n--- HTML OUTPUT (first 500 chars) ---");
console.log(page.html?.slice(0, 500));
console.log("\n--- FULL RESULT (JSON) ---");
console.log(JSON.stringify(result, null, 2).slice(0, 1000));
} catch (error: any) {
console.error("Error:", error.message);
process.exit(1);
} finally {
await reader.close();
}
}
main();