1import asyncio
2from pyppeteer import connect
3from hyperbrowser.client.async_client import AsyncHyperbrowser as Hyperbrowser
4
5HYPERBROWSER_API_KEY = "test-key"
6
7async def main():
8    client = Hyperbrowser(api_key=HYPERBROWSER_API_KEY)
9    session = await client.create_session()
10
11    ws_endpoint = session.websocket_url
12    browser = await connect(browserWSEndpoint=ws_endpoint, defaultViewport=None)
13
14    # Get pages
15    pages = await browser.pages()
16    if not pages:
17        raise Exception("No pages available")
18
19    page = pages(0)
20
21    # Navigate to a website
22    print("Navigating to Hacker News...")
23    await page.goto("https://news.ycombinator.com/")
24    page_title = await page.title()
25    print("Page title:", page_title)
26
27    await page.close()
28    await browser.close()
29    print("Session completed!")
30
31# Run the asyncio event loop
32asyncio.get_event_loop().run_until_complete(main())
33

Sumber

Krystian Wiśniewski
Krystian Wiśniewski is a dedicated Sports Reporter and Editor with a degree in Sports Journalism from He graduated with a degree in Journalism from the University of Warsaw. Bringing over 14 years of international reporting experience, Krystian has covered major sports events across Europe, Asia, and the United States of America. Known for his dynamic storytelling and in-depth analysis, he is passionate about capturing the excitement of sports for global audiences and currently leads sports coverage and editorial projects at Agen BRILink dan BRI.