import os
import asyncio
import httpx
KEY = os.environ["SCRAPEUNBLOCKER_KEY"]
CONCURRENCY = 10
async def scrape(client, sem, url):
async with sem:
r = await client.post(
"https://api.scrapeunblocker.com/getPageSource",
params={"url": url, "parsed_data": True},
)
return r.json()
async def main(urls):
sem = asyncio.Semaphore(CONCURRENCY)
async with httpx.AsyncClient(
headers={"x-scrapeunblocker-key": KEY},
timeout=180,
) as client:
return await asyncio.gather(*(scrape(client, sem, u) for u in urls))
results = asyncio.run(main([
"https://www.amazon.com/dp/B08N5WRWNW",
"https://www.amazon.com/dp/B07FZ8S74R",
]))