Skip to content

Commit c0f31b5

Browse files
committed
playwright basic
1 parent e1d024f commit c0f31b5

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import typer
2+
from playwright.sync_api import sync_playwright
3+
4+
app = typer.Typer()
5+
6+
7+
@app.command()
8+
def take_screenshot(
9+
path: str = "screenshot.png",
10+
url: str = "https://playwright.dev/",
11+
):
12+
with sync_playwright() as p:
13+
browser = p.chromium.launch()
14+
page = browser.new_page()
15+
page.goto(url=url)
16+
page.screenshot(path=path)
17+
browser.close()
18+
19+
20+
@app.command()
21+
def sandbox():
22+
with sync_playwright() as p:
23+
browser = p.chromium.launch(headless=False)
24+
page = browser.new_page()
25+
page.goto(url="https://search.yahoo.co.jp/realtime")
26+
for i in range(20):
27+
link = page.get_by_role(role="link", name=f"{i+1}th link", exact=True).text_content()
28+
print(link)
29+
browser.close()
30+
31+
32+
@app.command()
33+
def goodbye(name: str, formal: bool = False):
34+
if formal:
35+
print(f"Goodbye Ms. {name}. Have a good day.")
36+
else:
37+
print(f"Bye {name}!")
38+
39+
40+
if __name__ == "__main__":
41+
app()

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ langgraph-checkpoint-sqlite = "^1.0.4"
3535
playwright = "^1.47.0"
3636
lxml = "^5.3.0"
3737
nest-asyncio = "^1.6.0"
38+
typer = "^0.12.5"
3839

3940
[tool.poetry.group.dev.dependencies]
4041
pre-commit = "^3.8.0"

0 commit comments

Comments
 (0)