Update main.py 修改 user_agent ,避免无头模式被检测

修改 user_agent ,避免无头模式被检测。
This commit is contained in:
Shining Hu 2024-12-03 18:38:40 +08:00 committed by GitHub
parent e5fe928ce4
commit 6b035091d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -400,7 +400,10 @@ async def get_jd_pt_key(playwright: Playwright, user, mode) -> Union[str, None]:
proxy = None
browser = await playwright.chromium.launch(headless=headless, args=args, proxy=proxy)
context = await browser.new_context()
context = await browser.new_context(
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'
# 无头模式会被网站检测出来,所以加上这个。
)
try:
page = await context.new_page()
@ -481,7 +484,8 @@ async def get_jd_pt_key(playwright: Playwright, user, mode) -> Union[str, None]:
# 等待验证码通过
logger.info("等待获取cookie...")
await page.wait_for_selector('#msShortcutMenu', state='visible', timeout=120000)
await page.wait_for_load_state('load')
#不要傻等 msShortcutMenu 出现了。
cookies = await context.cookies()
for cookie in cookies: