import asyncio
import aiohttp
CONCURRENCY_LIMIT = 100
async def scrape_with_concurrency(urls: list[str]):
semaphore = asyncio.Semaphore(CONCURRENCY_LIMIT)
async def fetch(session, url):
async with semaphore:
proxy = "http://customer-USERNAME-cc-US:PASSWORD@gate.zentislabs.com:8080"
async with session.get(url, proxy=proxy) as resp:
return await resp.text()
async with aiohttp.ClientSession() as session:
tasks = [fetch(session, url) for url in urls]
results = await asyncio.gather(*tasks, return_exceptions=True)
success = sum(1 for r in results if not isinstance(r, Exception))
print(f"Completed: {success}/{len(urls)}")
return results