I was using playwright to scrape pages using Python. I know how to do the same using a script, but I was trying this in an interactive mode.
from playwright.sync_api import Playwright, sync_playwright, expect
import time
def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("https://www.wikipedia.org/")
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)
I tried to do this in interactive mode as:
>>> from playwright.sync_api import Playwright, sync_playwright, expect
>>> playwright = sync_playwright()
>>> browser = playwright.chromium.launch(headless=False)
But this gave me an error:
Traceback (most recent call last):
File "C:\Users\hpoddar\AppData\Local\Programs\Python\Python310\lib\idlelib\run.py", line 578, in runcode
exec(code, self.locals)
File "<pyshell#2>", line 1, in <module>
AttributeError: 'PlaywrightContextManager' object has no attribute 'chromium'