kaliiiiiiiiii / undetected-playwright-python

Undetected Python version of the Playwright testing and automation library.
https://playwright.dev/python/
Apache License 2.0
116 stars 13 forks source link

🎭 Playwright for Python

PyPI version

This is a patch of the original playwright implementation for Python.

It currently passes for sure (tested on Win10):

Warnings:

Demos (tested on Win 10)

drawing drawing

Dependencies

Installation

From PyPi (recommended)

execute in your shell console

pip install undetected-playwright-patch

Installation note for UNIX//Linux

Resolve "Permission Denied" error (click to expand) On UNIX-based OS, you might run into the following errors ``` Permission denied: '...python3.**/site-packages/undetected_playwright/driver/playwright.sh' ``` and ``` ...python3.**/site-packages/undetected_playwright/driver/node: Permission denied ``` To resolve them, simply run ```shell chmod +x .sh # so smth like: ...python3.**/site-packages/undetected_playwright/driver/playwright.sh ``` and ``` chmod +x # so smth like: ...python3.**/site-packages/undetected_playwright/driver/node ```

Build from this repo:

git clone https://github.com/kaliiiiiiiiii/undetected-playwright-python
cd undetected-playwright-python
python -m pip install -r local-requirements.txt
python build_patched.py

Example

import asyncio

# undetected-playwright here!
from undetected_playwright.async_api import async_playwright, Playwright

async def run(playwright: Playwright):
    args = []

    # disable navigator.webdriver:true flag
    args.append("--disable-blink-features=AutomationControlled")
    browser = await playwright.chromium.launch(headless=False,
                                               args=args)
    page = await browser.new_page()
    await page.goto("https://nowsecure.nl/#relax")
    input("Press ENTER to continue to Creep-JS:")
    await page.goto("https://nowsecure.nl/#relax")
    await page.goto("https://abrahamjuliot.github.io/creepjs/")
    input("Press ENTER to exit:")
    await browser.close()

async def main():
    async with async_playwright() as playwright:
        await run(playwright)

if __name__ == "__main__":
    loop = asyncio.ProactorEventLoop()
    loop.run_until_complete(main())
    # asyncio.run(main) # should work for non-Windows as well

# undetected-playwright here!
from undetected_playwright.sync_api import sync_playwright

with sync_playwright() as p:
    args = []

    # disable navigator.webdriver:true flag
    args.append("--disable-blink-features=AutomationControlled")
    browser = p.chromium.launch(args=args, headless=False)
    page = browser.new_page()
    page.goto("https://nowsecure.nl/#relax")
    input("Press ENTER to continue to Creep-JS:")
    page.goto("https://nowsecure.nl/#relax")
    page.goto("https://abrahamjuliot.github.io/creepjs/")
    input("Press ENTER to exit:")
    browser.close()

Documentation

See the original https://playwright.dev/python/docs/intro

API Reference

https://playwright.dev/python/docs/api/class-playwright

Sponsors

Capsolver

drawing

Patches

TODO's