安装
1、cmd中输入pip install playwright
2、安装完后接着输入playwright install 安装相关工具插件和浏览器驱动包
#pycharm终端输入下方命令启动电脑浏览器进行录制
#playwright codegen -o main.py
from playwright.sync_api import Playwright, sync_playwright, expect
def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("https://www.baidu.com/")
page.locator("#kw").click()
page.locator("#kw").fill("美女")
page.locator("#kw").press("Enter")
with page.expect_popup() as page1_info:
page.get_by_label("古风美女雍容华贵").click()
page1 = page1_info.value
page1.close()
page.close()
# ---------------------
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)
#pycharm终端输入下方命令录制手机浏览器
#playwright codegen --device="iPhone 13" -o main.py
#pycharm终端输入下方命令录制电脑浏览器登录17k后保存cookie到auth.json文件中
# playwright codegen --save-storage=auth.json https://www.17k.com
#pycharm终端输入下方命令携带着auth.json文件里的cookie登录17k不需要去登录输入密码
#playwright codegen --load-storage=auth.json https://www.17k.com -o main.py
标签:功能,playwright,录制,auth,json,close,page,输入
From: https://www.cnblogs.com/cy-xt/p/18122760