Skip to content

Commit

Permalink
docs(project): ✨ add example project to get source page
Browse files Browse the repository at this point in the history
  • Loading branch information
aprilahijriyan committed Jun 21, 2024
1 parent f651bee commit e5e158e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/get_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import asyncio
import logging

from cidipi.client import Browser
from cidipi.protocols import commands

logging.basicConfig(
level=logging.DEBUG, format="[%(levelname)s] [%(name)s] %(message)s"
)
logging.getLogger("websockets.client").disabled = True


async def main():
async with Browser(headless=True, remote_port=0) as browser:

async def run(url: str):
async with browser.new_tab() as tab:
await tab.execute(commands.Page.enable())
await tab.execute(commands.DOM.enable())
await tab.execute(commands.Page.navigate(url=url))
await asyncio.sleep(3)
result = await tab.execute(
commands.Runtime.evaluate(
expression="document.documentElement.outerHTML"
)
)
logging.info(result)

await run("https://www.google.com")


if __name__ == "__main__":
asyncio.run(main())

0 comments on commit e5e158e

Please sign in to comment.