File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed
Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,13 @@ python -m pytest -q
168168python -m build
169169```
170170
171+ ## Examples
172+
173+ Ready-to-run examples are available in ` examples/ ` :
174+
175+ - ` examples/sync_scrape.py `
176+ - ` examples/async_extract.py `
177+
171178## License
172179
173180MIT — see [ LICENSE] ( LICENSE ) .
Original file line number Diff line number Diff line change 1+ """
2+ Asynchronous extract example.
3+
4+ Run:
5+ export HYPERBROWSER_API_KEY="your_api_key"
6+ python examples/async_extract.py
7+ """
8+
9+ import asyncio
10+
11+ from hyperbrowser import AsyncHyperbrowser
12+ from hyperbrowser .models import StartExtractJobParams
13+
14+
15+ async def main () -> None :
16+ async with AsyncHyperbrowser () as client :
17+ result = await client .extract .start_and_wait (
18+ StartExtractJobParams (
19+ urls = ["https://hyperbrowser.ai" ],
20+ prompt = "Extract the main product value propositions as a list." ,
21+ ),
22+ poll_interval_seconds = 1.0 ,
23+ max_wait_seconds = 120.0 ,
24+ )
25+
26+ print (result .status )
27+ print (result .data )
28+
29+
30+ if __name__ == "__main__" :
31+ asyncio .run (main ())
Original file line number Diff line number Diff line change 1+ """
2+ Synchronous scrape example.
3+
4+ Run:
5+ export HYPERBROWSER_API_KEY="your_api_key"
6+ python examples/sync_scrape.py
7+ """
8+
9+ from hyperbrowser import Hyperbrowser
10+ from hyperbrowser .exceptions import HyperbrowserTimeoutError
11+ from hyperbrowser .models import ScrapeOptions , StartScrapeJobParams
12+
13+
14+ def main () -> None :
15+ with Hyperbrowser () as client :
16+ try :
17+ result = client .scrape .start_and_wait (
18+ StartScrapeJobParams (
19+ url = "https://hyperbrowser.ai" ,
20+ scrape_options = ScrapeOptions (formats = ["markdown" ]),
21+ ),
22+ poll_interval_seconds = 1.0 ,
23+ max_wait_seconds = 120.0 ,
24+ )
25+ except HyperbrowserTimeoutError :
26+ print ("Scrape job timed out." )
27+ return
28+
29+ if result .data and result .data .markdown :
30+ print (result .data .markdown [:500 ])
31+ else :
32+ print (f"Scrape finished with status={ result .status } and no markdown payload." )
33+
34+
35+ if __name__ == "__main__" :
36+ main ()
You can’t perform that action at this time.
0 commit comments