Skip to content

Commit

Permalink
add scrape extraction examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mazen-r committed Nov 8, 2024
1 parent 731e5ca commit 48de0b4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/deno/deno_examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ export async function JSRender(apiKey: string) {
console.log(scrape_result.result.browser_data);
}

/* Use AI extraction capabilities with the the web scraping API
* all Extraction API methods are supported, see below examples for more
*/
export async function scrapeExtraction(apiKey: string) {
const client = new ScrapflyClient({ key: apiKey});

let scrape_result = await client.scrape(
new ScrapeConfig({
url: 'https://web-scraping.dev/product/1',
// enable browsers:
render_js: true,
// use LLM prompt for auto parsing
extraction_prompt: "Extract the product specification in json format",
})
);

// access the extraction result
console.log("extraction result:");
console.log(scrape_result.result.extracted_data);
}


/* Scrapfly Extraction API offers LLM (Language Learning Model) based extraction
* This example demonstrates how to use LLM query HTML files
* https://scrapfly.io/docs/extraction-api/llm-prompt
Expand Down
22 changes: 22 additions & 0 deletions examples/node_commonjs/commonjs_examples.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ async function JSRender(apiKey) {
console.log(scrape_result.result.browser_data);
}

/* Use AI extraction capabilities with the the web scraping API
* all Extraction API methods are supported, see below examples for more
*/
async function scrapeExtraction(apiKey) {
const client = new ScrapflyClient({ key: apiKey});

let scrape_result = await client.scrape(
new ScrapeConfig({
url: 'https://web-scraping.dev/product/1',
// enable browsers:
render_js: true,
// use LLM prompt for auto parsing
extraction_prompt: "Extract the product specification in json format",
})
);

// access the extraction result
console.log("extraction result:");
console.log(scrape_result.result.extracted_data);
}

/* Scrapfly Extraction API offers LLM (Language Learning Model) based extraction
* This example demonstrates how to use LLM query HTML files
* https://scrapfly.io/docs/extraction-api/llm-prompt
Expand Down Expand Up @@ -233,6 +254,7 @@ module.exports = {
getAccount,
basicGet,
JSRender,
scrapeExtraction,
extractionLLM,
extractionAutoExtract,
extractionTemplates,
Expand Down

0 comments on commit 48de0b4

Please sign in to comment.