Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:
from playwright.sync_api import sync_playwright, Playwright
def run(playwright: Playwright):
chromium = playwright.chromium
browser = chromium.launch()
page = browser.new_page()
page.goto("http://example.com")
browser.close()
with sync_playwright() as playwright:
run(playwright)
import asyncio
from playwright.async_api import async_playwright, Playwright
async def run(playwright: Playwright):
chromium = playwright.chromium
browser = await chromium.launch()
page = await browser.new_page()
await page.goto("http://example.com")
await browser.close()
async def main():
async with async_playwright() as playwright:
await run(playwright)
asyncio.run(main())
Methods stopAdded before v1.9 playwright.stop
Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in REPL applications.
from playwright.sync_api import sync_playwright
playwright = sync_playwright().start()
browser = playwright.chromium.launch()
page = browser.new_page()
page.goto("https://playwright.dev/")
page.screenshot(path="example.png")
browser.close()
playwright.stop()
Usage
Returns
Properties chromiumAdded before v1.9 playwright.chromiumThis object can be used to launch or connect to Chromium, returning instances of Browser.
Usage
Type
devicesAdded before v1.9 playwright.devicesReturns a dictionary of devices to be used with browser.new_context() or browser.new_page().
from playwright.sync_api import sync_playwright, Playwright
def run(playwright: Playwright):
webkit = playwright.webkit
iphone = playwright.devices["iPhone 6"]
browser = webkit.launch()
context = browser.new_context(**iphone)
page = context.new_page()
page.goto("http://example.com")
browser.close()
with sync_playwright() as playwright:
run(playwright)
import asyncio
from playwright.async_api import async_playwright, Playwright
async def run(playwright: Playwright):
webkit = playwright.webkit
iphone = playwright.devices["iPhone 6"]
browser = await webkit.launch()
context = await browser.new_context(**iphone)
page = await context.new_page()
await page.goto("http://example.com")
await browser.close()
async def main():
async with async_playwright() as playwright:
await run(playwright)
asyncio.run(main())
Usage
Type
firefoxAdded before v1.9 playwright.firefoxThis object can be used to launch or connect to Firefox, returning instances of Browser.
Usage
Type
requestAdded in: v1.16 playwright.requestExposes API that can be used for the Web API testing.
Usage
Type
selectorsAdded before v1.9 playwright.selectorsSelectors can be used to install custom selector engines. See extensibility for more information.
Usage
Type
webkitAdded before v1.9 playwright.webkitThis object can be used to launch or connect to WebKit, returning instances of Browser.
Usage
Type
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4