Loading...
Loading...
Web scraping from TypeScript or JavaScript with the Scrapfly SDK (`scrapfly-sdk`). Use when the user asks to scrape a URL, bypass anti-bot protection, render JavaScript, capture screenshots, or extract structured data from Node.js, Deno, or Bun.
npx skill4agent add scrapfly/skills scrapfly-sdk-typescriptscrapfly-sdknpm install scrapfly-sdk
# Deno / JSR: import from 'jsr:@scrapfly/scrapfly-sdk'
export SCRAPFLY_API_KEY="your-api-key"import { ScrapflyClient, ScrapeConfig } from 'scrapfly-sdk';
const client = new ScrapflyClient({ key: process.env.SCRAPFLY_API_KEY });
const result = await client.scrape(
new ScrapeConfig({ url: 'https://web-scraping.dev/products' }),
);
console.log(result.result.content);ScrapeConfigconst result = await client.scrape(
new ScrapeConfig({
url: 'https://web-scraping.dev/products',
unblocker: true, // bypass anti-bot
country: 'us', // proxy country (ISO 3166-1 alpha-2)
proxy_pool: 'public_residential_pool',
render_js: true, // headless browser rendering
wait_for_selector: 'div.product', // requires render_js
rendering_wait: 5000, // ms, requires render_js
format: 'markdown', // raw | clean_html | json | markdown | text
}),
);import { ScreenshotConfig, ExtractionConfig } from 'scrapfly-sdk';
const shot = await client.screenshot(
new ScreenshotConfig({ url: 'https://web-scraping.dev/products' }),
);
// shot.image is the binary image data
const html = (await client.scrape(
new ScrapeConfig({ url: 'https://web-scraping.dev/reviews' }),
)).result.content;
const data = await client.extract(
new ExtractionConfig({
body: html,
content_type: 'text/html',
extraction_prompt: 'extract the reviews as JSON with fields: review, date, rating, author',
}),
);
console.log(data.data);const configs = [
new ScrapeConfig({ url: 'https://web-scraping.dev/products?page=1' }),
new ScrapeConfig({ url: 'https://web-scraping.dev/products?page=2' }),
];
for await (const result of client.concurrentScrape(configs)) {
console.log(result.result.content.slice(0, 100));
}render_js: truerendering_waitwait_for_selectorproxy_pool: 'public_residential_pool'unblocker: trueunblockeraspaspaspunblockerformat: 'markdown'keyprocess.env.SCRAPFLY_API_KEYresult.result.content