mirror of
https://github.com/vndangkhoa/purestream.git
synced 2026-04-05 01:17:58 +07:00
Fix anti-bot detection with playwright-stealth
This commit is contained in:
parent
0e240218b4
commit
a89b261fa2
2 changed files with 9 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ import json
|
||||||
import os
|
import os
|
||||||
from typing import List, Dict, Optional
|
from typing import List, Dict, Optional
|
||||||
from playwright.async_api import async_playwright, Response, Browser, BrowserContext
|
from playwright.async_api import async_playwright, Response, Browser, BrowserContext
|
||||||
|
from playwright_stealth import stealth_async
|
||||||
|
|
||||||
|
|
||||||
COOKIES_FILE = "cookies.json"
|
COOKIES_FILE = "cookies.json"
|
||||||
|
|
@ -158,6 +159,7 @@ class PlaywrightManager:
|
||||||
)
|
)
|
||||||
|
|
||||||
cls._vnc_page = await cls._vnc_context.new_page()
|
cls._vnc_page = await cls._vnc_context.new_page()
|
||||||
|
await stealth_async(cls._vnc_page)
|
||||||
await cls._vnc_page.goto("https://www.tiktok.com/login", wait_until="domcontentloaded")
|
await cls._vnc_page.goto("https://www.tiktok.com/login", wait_until="domcontentloaded")
|
||||||
|
|
||||||
cls._vnc_active = True
|
cls._vnc_active = True
|
||||||
|
|
@ -258,6 +260,7 @@ class PlaywrightManager:
|
||||||
)
|
)
|
||||||
|
|
||||||
page = await context.new_page()
|
page = await context.new_page()
|
||||||
|
await stealth_async(page)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Navigate to TikTok login page
|
# Navigate to TikTok login page
|
||||||
|
|
@ -376,6 +379,7 @@ class PlaywrightManager:
|
||||||
)
|
)
|
||||||
|
|
||||||
page = await context.new_page()
|
page = await context.new_page()
|
||||||
|
await stealth_async(page)
|
||||||
|
|
||||||
# Navigate to TikTok login
|
# Navigate to TikTok login
|
||||||
await page.goto("https://www.tiktok.com/login", wait_until="domcontentloaded")
|
await page.goto("https://www.tiktok.com/login", wait_until="domcontentloaded")
|
||||||
|
|
@ -480,6 +484,7 @@ class PlaywrightManager:
|
||||||
await context.add_cookies(cookies)
|
await context.add_cookies(cookies)
|
||||||
|
|
||||||
page = await context.new_page()
|
page = await context.new_page()
|
||||||
|
await stealth_async(page)
|
||||||
|
|
||||||
# Set up response listener
|
# Set up response listener
|
||||||
page.on("response", handle_response)
|
page.on("response", handle_response)
|
||||||
|
|
@ -640,6 +645,7 @@ class PlaywrightManager:
|
||||||
await context.add_cookies(cookies)
|
await context.add_cookies(cookies)
|
||||||
|
|
||||||
page = await context.new_page()
|
page = await context.new_page()
|
||||||
|
await stealth_async(page)
|
||||||
page.on("response", handle_response)
|
page.on("response", handle_response)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -718,6 +724,7 @@ class PlaywrightManager:
|
||||||
await context.add_cookies(cookies)
|
await context.add_cookies(cookies)
|
||||||
|
|
||||||
page = await context.new_page()
|
page = await context.new_page()
|
||||||
|
await stealth_async(page)
|
||||||
page.on("response", handle_response)
|
page.on("response", handle_response)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,5 @@ python-multipart
|
||||||
websockets
|
websockets
|
||||||
python-dotenv
|
python-dotenv
|
||||||
crawl4ai
|
crawl4ai
|
||||||
|
playwright
|
||||||
|
playwright-stealth
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue