Skip to content

Commit b95b2db

Browse files
strzibnyclaude
andcommitted
Fix Extract API follow-link example and smoke test callbacks
Use books.toscrape.com in the README follow-link example, since example.com has no inline links, and guard against a missing link. In the smoke tests, await extract with a callback and check that the callback received the returned result, so a skipped callback fails the test. Co-authored-by: Claude Opus 5.5 (xhigh effort) <noreply@anthropic.com>
1 parent 99d8efd commit b95b2db

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ Settings such as `device` or `include_tags` are not carried over, so pass them
156156
again if needed:
157157

158158
```js
159-
const page = await extract({ url: "https://example.com/" });
160-
const linkedPage = await extract({ url: page.inline_links[0].link });
159+
const page = await extract({ url: "https://books.toscrape.com/" });
160+
const link = page.inline_links?.[0]?.link;
161+
if (link) {
162+
const linkedPage = await extract({ url: link });
163+
console.log(linkedPage.page_information);
164+
}
161165
```
162166
163167
To get only the Markdown, use `getMd` with the `extract` engine:

‎smoke_tests/commonjs/commonjs.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,17 @@ const run = async () => {
129129

130130
{
131131
console.log("extract");
132-
const json = await extract({ url: "https://example.com/", api_key: apiKey });
132+
let callbackJson;
133+
const json = await extract(
134+
{ url: "https://example.com/", api_key: apiKey },
135+
(result) => {
136+
callbackJson = result;
137+
},
138+
);
133139
if (!json["page_information"]) throw new Error("No page information");
134-
135-
extract({ url: "https://example.com/", api_key: apiKey }, (json) => {
136-
if (!json["page_information"]) throw new Error("No page information");
137-
});
140+
if (callbackJson !== json) {
141+
throw new Error("Callback result does not match returned result");
142+
}
138143
}
139144

140145
{

‎smoke_tests/esm/esm.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,17 @@ let searchId;
132132

133133
{
134134
console.log("extract");
135-
const json = await extract({ url: "https://example.com/", api_key: apiKey });
135+
let callbackJson;
136+
const json = await extract(
137+
{ url: "https://example.com/", api_key: apiKey },
138+
(result) => {
139+
callbackJson = result;
140+
},
141+
);
136142
if (!json["page_information"]) throw new Error("No page information");
137-
138-
extract({ url: "https://example.com/", api_key: apiKey }, (json) => {
139-
if (!json["page_information"]) throw new Error("No page information");
140-
});
143+
if (callbackJson !== json) {
144+
throw new Error("Callback result does not match returned result");
145+
}
141146
}
142147

143148
{

0 commit comments

Comments
 (0)