国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python palywright庫基本使用

瀏覽:68日期:2022-06-29 14:28:47

開源方:微軟

安裝:pip install playwright;python -m playwright install

特點:自動化腳本錄制;有同步、異步api

生成代碼指令:python -m playwright codegen其他:需要Python 3.7及以上;官方api為node版本,python版本待補充

同步:關鍵字為:sync_playwright

from time import sleepfrom playwright import sync_playwrightwith sync_playwright() as p: for browser_type in [p.chromium, p.firefox, p.webkit]: browser = browser_type.launch(headless=False) # 默認無頭,這樣為有頭模式 page = browser.newPage() page.goto(’http://baidu.com’) page.fill('input[name='wd']', 'AirPython') with page.expect_navigation(): page.press('input[name='wd']', 'Enter') page.waitForSelector('text=百度熱榜') page.screenshot(path=f’example-{browser_type.name}.png’) sleep(5) browser.close()異步:關鍵字為:async_playwright

import asynciofrom playwright import async_playwrightasync def main(): async with async_playwright() as p: for browser_type in [p.chromium, p.firefox, p.webkit]: browser = await browser_type.launch(headless=False) page = await browser.newPage() await page.goto(’http://baidu.com’) await page.fill('input[name='wd']', 'AirPython') await page.press('input[name='wd']', 'Enter') await page.waitForSelector('text=百度熱榜') await page.screenshot(path=f’example-{browser_type.name}.png’) await browser.close()asyncio.get_event_loop().run_until_complete(main())集成 pytest 測試

@pytest.fixture(scope='session')def test_playwright_is_visible_on_google(page): page.goto('https://www.google.com') page.type('input[name=q]', 'Playwright GitHub') page.click('input[type=submit]') page.waitForSelector('text=microsoft/Playwright')執行 JS 代碼

from playwright import sync_playwrightwith sync_playwright() as p: browser = p.firefox.launch() page = browser.newPage() page.goto(’https://www.example.com/’) dimensions = page.evaluate(’’’() => { return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, deviceScaleFactor: window.devicePixelRatio } }’’’) print(dimensions) browser.close()中斷網絡請求

from playwright import sync_playwrightwith sync_playwright() as p: browser = p.chromium.launch() page = browser.newPage()def log_and_continue_request(route, request): print(request.url) route.continue_()記錄并繼續所有網絡請求

page.route(’**’, lambda route, request: log_and_continue_request(route, request))page.goto(’http://todomvc.com’)browser.close()

以上就是python palywright庫基本使用的詳細內容,更多關于python palywright庫的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 平泉县| 鄂温| 西青区| 留坝县| 弥勒县| 铜山县| 平潭县| 改则县| 宿迁市| 大同县| 南丰县| 特克斯县| 夏邑县| 江永县| 洛扎县| 南宁市| 肥乡县| 永吉县| 磐安县| 勐海县| 乌兰浩特市| 庆城县| 高台县| 白河县| 桦川县| 杭锦后旗| 雷山县| 景泰县| 西贡区| 旺苍县| 兴化市| 兴义市| 石阡县| 瓮安县| 武宁县| 勃利县| 新丰县| 赞皇县| 桐梓县| 繁峙县| 湘潭县|