久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python palywright庫(kù)基本使用

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

開源方:微軟

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

特點(diǎn):自動(dòng)化腳本錄制;有同步、異步api

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

同步:關(guān)鍵字為: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) # 默認(rèn)無(wú)頭,這樣為有頭模式 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()異步:關(guān)鍵字為: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 測(cè)試

@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')執(zhí)行 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()中斷網(wǎng)絡(luò)請(qǐng)求

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_()記錄并繼續(xù)所有網(wǎng)絡(luò)請(qǐng)求

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

以上就是python palywright庫(kù)基本使用的詳細(xì)內(nèi)容,更多關(guān)于python palywright庫(kù)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 肇源县| 海阳市| 荃湾区| 习水县| 尤溪县| 延寿县| 兖州市| 韶山市| 乌兰察布市| 德惠市| 甘肃省| 永州市| 盐边县| 晋州市| 茶陵县| 乌什县| 平邑县| 镇雄县| 鄂托克旗| 无极县| 无为县| 忻城县| 遵义县| 梁河县| 安多县| 长寿区| 鸡泽县| 沙田区| 前郭尔| 金寨县| 正镶白旗| 普兰店市| 房产| 社会| 百色市| 宿松县| 清涧县| 墨脱县| 和林格尔县| 巴马| 青浦区|