Skip to content

Commit 48de0b4

Browse files
committed
add scrape extraction examples
1 parent 731e5ca commit 48de0b4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

examples/deno/deno_examples.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@ export async function JSRender(apiKey: string) {
8181
console.log(scrape_result.result.browser_data);
8282
}
8383

84+
/* Use AI extraction capabilities with the the web scraping API
85+
* all Extraction API methods are supported, see below examples for more
86+
*/
87+
export async function scrapeExtraction(apiKey: string) {
88+
const client = new ScrapflyClient({ key: apiKey});
89+
90+
let scrape_result = await client.scrape(
91+
new ScrapeConfig({
92+
url: 'https://web-scraping.dev/product/1',
93+
// enable browsers:
94+
render_js: true,
95+
// use LLM prompt for auto parsing
96+
extraction_prompt: "Extract the product specification in json format",
97+
})
98+
);
99+
100+
// access the extraction result
101+
console.log("extraction result:");
102+
console.log(scrape_result.result.extracted_data);
103+
}
104+
105+
84106
/* Scrapfly Extraction API offers LLM (Language Learning Model) based extraction
85107
* This example demonstrates how to use LLM query HTML files
86108
* https://scrapfly.io/docs/extraction-api/llm-prompt

examples/node_commonjs/commonjs_examples.cjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ async function JSRender(apiKey) {
8181
console.log(scrape_result.result.browser_data);
8282
}
8383

84+
/* Use AI extraction capabilities with the the web scraping API
85+
* all Extraction API methods are supported, see below examples for more
86+
*/
87+
async function scrapeExtraction(apiKey) {
88+
const client = new ScrapflyClient({ key: apiKey});
89+
90+
let scrape_result = await client.scrape(
91+
new ScrapeConfig({
92+
url: 'https://web-scraping.dev/product/1',
93+
// enable browsers:
94+
render_js: true,
95+
// use LLM prompt for auto parsing
96+
extraction_prompt: "Extract the product specification in json format",
97+
})
98+
);
99+
100+
// access the extraction result
101+
console.log("extraction result:");
102+
console.log(scrape_result.result.extracted_data);
103+
}
104+
84105
/* Scrapfly Extraction API offers LLM (Language Learning Model) based extraction
85106
* This example demonstrates how to use LLM query HTML files
86107
* https://scrapfly.io/docs/extraction-api/llm-prompt
@@ -233,6 +254,7 @@ module.exports = {
233254
getAccount,
234255
basicGet,
235256
JSRender,
257+
scrapeExtraction,
236258
extractionLLM,
237259
extractionAutoExtract,
238260
extractionTemplates,

0 commit comments

Comments
 (0)