https://www.apartmentguide.com/apartments/Texas/Plano/
from playwright.async_api import async_playwright
import asyncio
async def run_playwright():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto("https://www.example.com")
await page.screenshot(path="example.png")
await browser.close()
async def main():
await run_playwright()
asyncio.get_event_loop().run_until_complete(main())
RuntimeError: This event loop is already running
def run(playwright: Playwright):
chromium = playwright.chromium # or "firefox" or "webkit".
browser = chromium.launch()
page = browser.new_page()
page.goto("http://example.com")
# other actions...
browser.close()
with sync_playwright() as playwright:
run(playwright)
Error: It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.