-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright_hello.py
More file actions
30 lines (23 loc) · 893 Bytes
/
Copy pathplaywright_hello.py
File metadata and controls
30 lines (23 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import asyncio
from playwright.async_api import async_playwright
async def scrape_dynamic_page():
"""
A simple example of using Playwright to scrape a dynamic page.
"""
async with async_playwright() as p:
# Launch the browser
browser = await p.chromium.launch(headless=True)
page = await browser.new_page()
url = "https://quotes.toscrape.com"
print(f"--- Browsing {url} with Playwright ---")
# Navigate to the page
await page.goto(url)
# Wait for a specific element (useful for JS-heavy sites)
await page.wait_for_selector("h1")
# Extract data
title = await page.inner_text("h1")
print(f"Page Title: {title}")
# Close the browser
await browser.close()
if __name__ == "__main__":
asyncio.run(scrape_dynamic_page())