Skip to content

Commit 64838b5

Browse files
committed
Add --extract-schema and --extract-prompt flags to scrape command
Passes extract config to the SDK read() call. Displays extracted data as JSON when present in the response.
1 parent 0006592 commit 64838b5

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/commands/scrape.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export function registerScrapeCommand(program: Command): void {
1717
.option("--wait-for <selector>", "Wait for CSS selector before scraping")
1818
.option("--timeout <ms>", "Timeout in milliseconds", "30000")
1919
.option("--proxy-mode <mode>", "Proxy mode: standard (default) or premium")
20+
.option("--extract-schema <json>", "JSON schema for structured data extraction")
21+
.option("--extract-prompt <text>", "Natural language prompt for extraction")
2022
.action(async (rawUrl: string, opts) => {
2123
const url = normalizeUrl(rawUrl);
2224
const apiKey = getApiKey();
@@ -34,6 +36,14 @@ export function registerScrapeCommand(program: Command): void {
3436
const spinner = scrapeSpinner();
3537

3638
try {
39+
// Build extract config if flags provided
40+
const extract = opts.extractSchema || opts.extractPrompt
41+
? {
42+
schema: opts.extractSchema ? JSON.parse(opts.extractSchema) : undefined,
43+
prompt: opts.extractPrompt,
44+
}
45+
: undefined;
46+
3747
const result = await client.read({
3848
url,
3949
formats,
@@ -43,6 +53,7 @@ export function registerScrapeCommand(program: Command): void {
4353
waitForSelector: opts.waitFor,
4454
timeoutMs: timeout,
4555
proxyMode: opts.proxyMode,
56+
extract,
4657
});
4758

4859
if (result.kind === "scrape") {
@@ -61,6 +72,12 @@ export function registerScrapeCommand(program: Command): void {
6172
if (requestedFormat === "screenshot") return;
6273
}
6374

75+
// Extracted data output
76+
if ((data as Record<string, unknown>).extracted) {
77+
info("\nExtracted data:");
78+
outputJson((data as Record<string, unknown>).extracted);
79+
}
80+
6481
// Content output
6582
const content = data.markdown || data.html || "";
6683
if (opts.output && !opts.output.endsWith(".png")) {

0 commit comments

Comments
 (0)