Compare commits
No commits in common. "8af6709f3b7465172be26601c738928a36d70ef8" and "17cd46b761a130fa2ff9f6020f55957d1db13014" have entirely different histories.
8af6709f3b
...
17cd46b761
@ -1 +0,0 @@
|
|||||||
playwright>=1.44.0
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from playwright.async_api import async_playwright
|
|
||||||
|
|
||||||
|
|
||||||
OUTPUT_FILE: Path = Path("screenshot.png")
|
|
||||||
TARGET_URL: str = "https://linux.org"
|
|
||||||
|
|
||||||
|
|
||||||
async def capture_screenshot(url: str, output_path: Path) -> None:
|
|
||||||
"""Navigate to a URL, wait for the page to load, and save a screenshot.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
url: The URL to navigate to.
|
|
||||||
output_path: The file path where the screenshot will be saved.
|
|
||||||
"""
|
|
||||||
async with async_playwright() as pw:
|
|
||||||
# Launch Chromium in headless mode
|
|
||||||
browser = await pw.chromium.launch(headless=True)
|
|
||||||
page = await browser.new_page(
|
|
||||||
viewport={"width": 1280, "height": 900}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Navigate and wait until network is idle (page fully loaded)
|
|
||||||
await page.goto(url, wait_until="networkidle", timeout=30_000)
|
|
||||||
|
|
||||||
# Persist screenshot to disk
|
|
||||||
await page.screenshot(path=str(output_path), full_page=False)
|
|
||||||
await browser.close()
|
|
||||||
|
|
||||||
print(f"Screenshot saved to {output_path.resolve()}")
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
"""Entry point: capture a screenshot of the target URL."""
|
|
||||||
asyncio.run(capture_screenshot(TARGET_URL, OUTPUT_FILE))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
Loading…
Reference in New Issue
Block a user