import { ReaderClient, ProxyConfig } from "@vakra-dev/reader";
async function scrapeWithProxies() {
const proxies: ProxyConfig[] = [
{
type: "residential",
host: "us-proxy.example.com",
port: 8080,
username: "user",
password: "pass",
country: "us",
},
{
type: "residential",
host: "uk-proxy.example.com",
port: 8080,
username: "user",
password: "pass",
country: "uk",
},
{
type: "residential",
host: "de-proxy.example.com",
port: 8080,
username: "user",
password: "pass",
country: "de",
},
];
const reader = new ReaderClient({
proxies,
proxyRotation: "round-robin",
browserPool: { size: 5 },
});
try {
const urls = [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3",
"https://example.com/page4",
"https://example.com/page5",
];
const result = await reader.scrape({
urls,
batchConcurrency: 3,
onProgress: (p) => {
console.log(`[${p.completed}/${p.total}] ${p.currentUrl}`);
},
});
console.log(`Scraped ${result.batchMetadata.successfulUrls} URLs`);
} finally {
await reader.close();
}
}
scrapeWithProxies().catch(console.error);