File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed
Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -257,12 +257,14 @@ Contributor workflow details are available in [CONTRIBUTING.md](CONTRIBUTING.md)
257257
258258Ready-to-run examples are available in ` examples/ ` :
259259
260+ - ` examples/async_batch_fetch.py `
260261- ` examples/async_crawl.py `
261262- ` examples/async_extract.py `
262263- ` examples/async_scrape.py `
263264- ` examples/async_session_list.py `
264265- ` examples/async_web_fetch.py `
265266- ` examples/async_web_search.py `
267+ - ` examples/sync_batch_fetch.py `
266268- ` examples/sync_crawl.py `
267269- ` examples/sync_extract.py `
268270- ` examples/sync_scrape.py `
Original file line number Diff line number Diff line change 1+ """
2+ Asynchronous batch fetch example.
3+
4+ Run:
5+ export HYPERBROWSER_API_KEY="your_api_key"
6+ python3 examples/async_batch_fetch.py
7+ """
8+
9+ import asyncio
10+
11+ from hyperbrowser import AsyncHyperbrowser
12+ from hyperbrowser .exceptions import HyperbrowserTimeoutError
13+ from hyperbrowser .models import StartBatchFetchJobParams
14+
15+
16+ async def main () -> None :
17+ async with AsyncHyperbrowser () as client :
18+ try :
19+ result = await client .web .batch_fetch .start_and_wait (
20+ StartBatchFetchJobParams (
21+ urls = [
22+ "https://hyperbrowser.ai" ,
23+ "https://docs.hyperbrowser.ai" ,
24+ ],
25+ ),
26+ poll_interval_seconds = 1.0 ,
27+ max_wait_seconds = 120.0 ,
28+ )
29+ except HyperbrowserTimeoutError :
30+ print ("Batch fetch job timed out." )
31+ return
32+
33+ print (f"Status: { result .status } " )
34+ print (f"Fetched pages: { len (result .data or [])} " )
35+
36+
37+ if __name__ == "__main__" :
38+ asyncio .run (main ())
Original file line number Diff line number Diff line change 1+ """
2+ Synchronous batch fetch example.
3+
4+ Run:
5+ export HYPERBROWSER_API_KEY="your_api_key"
6+ python3 examples/sync_batch_fetch.py
7+ """
8+
9+ from hyperbrowser import Hyperbrowser
10+ from hyperbrowser .exceptions import HyperbrowserTimeoutError
11+ from hyperbrowser .models import StartBatchFetchJobParams
12+
13+
14+ def main () -> None :
15+ with Hyperbrowser () as client :
16+ try :
17+ result = client .web .batch_fetch .start_and_wait (
18+ StartBatchFetchJobParams (
19+ urls = [
20+ "https://hyperbrowser.ai" ,
21+ "https://docs.hyperbrowser.ai" ,
22+ ],
23+ ),
24+ poll_interval_seconds = 1.0 ,
25+ max_wait_seconds = 120.0 ,
26+ )
27+ except HyperbrowserTimeoutError :
28+ print ("Batch fetch job timed out." )
29+ return
30+
31+ print (f"Status: { result .status } " )
32+ print (f"Fetched pages: { len (result .data or [])} " )
33+
34+
35+ if __name__ == "__main__" :
36+ main ()
You can’t perform that action at this time.
0 commit comments