mirror of
https://github.com/daijro/camoufox.git
synced 2026-08-18 16:00:58 +00:00
d6540b52ce
* example files * contributing guides * simple service test * run tests in sync * update pr template * pip updates * Update README.md * typo fixes * undo pip package update lol * upgraded service test * undo injections * test with proxies * auto set timezone and proxy url * delete checks bundle * split up service tests * split up build tests * rename service tests to service tester * Update CONTRIBUTING.md * fix entry vs exit ip * allow alpha versions * fix patch issues on macos * bidirectional patch * Add note on experimental pip package
39 lines
917 B
Python
39 lines
917 B
Python
"""
|
|
Async version of the example — useful for scraping multiple pages concurrently.
|
|
|
|
Install deps:
|
|
pip install cloverlabs-camoufox
|
|
python -m camoufox fetch
|
|
"""
|
|
|
|
import asyncio
|
|
from camoufox.async_api import AsyncCamoufox
|
|
|
|
URLS = [
|
|
"https://httpbin.org/headers",
|
|
"https://httpbin.org/user-agent",
|
|
"https://httpbin.org/ip",
|
|
]
|
|
|
|
|
|
async def scrape(page, url: str) -> dict:
|
|
await page.goto(url)
|
|
body = await page.inner_text("body")
|
|
return {"url": url, "body": body[:300]}
|
|
|
|
|
|
async def main():
|
|
async with AsyncCamoufox(headless=True) as browser:
|
|
context = await browser.new_context()
|
|
|
|
pages = [await context.new_page() for _ in URLS]
|
|
results = await asyncio.gather(*[scrape(p, u) for p, u in zip(pages, URLS)])
|
|
|
|
for r in results:
|
|
print(f"\n--- {r['url']} ---")
|
|
print(r["body"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|