add stealth
This commit is contained in:
@@ -4,6 +4,7 @@ import time
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from playwright.sync_api import sync_playwright, Page, Browser
|
from playwright.sync_api import sync_playwright, Page, Browser
|
||||||
|
from playwright_stealth import Stealth
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
@@ -194,21 +195,16 @@ def download_all_invoices() -> list[Path]:
|
|||||||
output_dir.mkdir(parents=True, exist_ok=True)
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
saved = []
|
saved = []
|
||||||
|
|
||||||
|
stealth = Stealth()
|
||||||
|
|
||||||
with sync_playwright() as p:
|
with sync_playwright() as p:
|
||||||
browser = p.chromium.launch(
|
browser = p.chromium.launch(
|
||||||
headless=Config.BROWSER_HEADLESS,
|
headless=Config.BROWSER_HEADLESS,
|
||||||
args=["--disable-blink-features=AutomationControlled"],
|
args=["--disable-blink-features=AutomationControlled"],
|
||||||
)
|
)
|
||||||
context = browser.new_context(
|
context = browser.new_context()
|
||||||
user_agent=(
|
stealth.apply_stealth_sync(context)
|
||||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
|
|
||||||
"(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
page.add_init_script(
|
|
||||||
"Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
|
|
||||||
)
|
|
||||||
page.set_default_timeout(Config.BROWSER_TIMEOUT)
|
page.set_default_timeout(Config.BROWSER_TIMEOUT)
|
||||||
|
|
||||||
login(page)
|
login(page)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
(python3.withPackages (ps: [
|
(python3.withPackages (ps: [
|
||||||
ps.playwright
|
ps.playwright
|
||||||
|
ps.playwright-stealth
|
||||||
ps."python-dotenv"
|
ps."python-dotenv"
|
||||||
]))
|
]))
|
||||||
playwright-driver.browsers
|
playwright-driver.browsers
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
playwright>=1.40.0
|
playwright>=1.40.0
|
||||||
|
playwright-stealth>=1.0.6
|
||||||
python-dotenv>=1.0.0
|
python-dotenv>=1.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user