Closed glira closed 1 year ago
You can add this line of code to customize ua.
context = await browser.new_context(
user_agent='My user agent'
)
This is playwright api docs. https://playwright.dev/python/docs/emulation#user-agent
Example:
import asyncio
from playwright.async_api import async_playwright
from cf_clearance import async_cf_retry, async_stealth
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False, proxy={"server": "socks5://localhost:7890"})
context = await browser.new_context(
user_agent='My user agent'
)
page = await context.new_page()
await async_stealth(page, pure=True)
await page.goto('https://nowsecure.nl')
res = await async_cf_retry(page)
if res:
cookies = await page.context.cookies()
for cookie in cookies:
if cookie.get('name') == 'cf_clearance':
cf_clearance_value = cookie.get('value')
print(cf_clearance_value)
ua = await page.evaluate('() => {return navigator.userAgent}')
print(ua)
else:
print("cf challenge fail")
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
Docker image will be updated later.
We need of support to custom user-agent, thank for brilliant project , time and effort