Python playwright 笔记

1.官网 https://playwright.nodejs.cn/docs/api/class-playwright

2.Playwright for Python:https://playwright.bootcss.com/python/docs/intro

3.入门笔记:https://www.byhy.net/

4.playwright使用教程python版本-页面监听器、状态检测、执行JS、网络Mock等使用API  https://www.bilibili.com/opus/860060080235610135

5.《最新出炉》系列小成篇 https://www.cnblogs.com/du-hong/category/2309756.html

 

from playwright.sync_api import sync_playwright

playwright = sync_playwright().start()
browser = playwright.chromium.launch(headless=False,
                                     executable_path=r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
                                     args=['--start-maximized'])
context = browser.new_context(no_viewport=True)
page = context.new_page()
page.goto("http://10.151.14.107:12345/")
page.locator(".my-project").click()

page.locator("#user").fill("admin")
page.locator('#pwd').fill("123456")
page.locator("#btnLogin").click()

page.locator('#txtName').fill('test')
page.locator('#btnSearch').click()
page.wait_for_timeout(1000)

print("Start get information...")

table = page.locator('//*[@id="divTable"]/table/tbody/tr').all()
for row in table:
    row_text = row.inner_text()
    row_list = row_text.split('\t')
    print(f"ID is {row_list[0]}  and Name is {row_list[1]}")

print("End get information... 88 ...")

browser.close()
playwright.stop()

  

posted @ 2024-12-12 16:06  三叶草╮  阅读(8)  评论(0编辑  收藏  举报