Merge pull request #234 from Chang-Tao/fix/douyin-cookie-auth
fix(douyin): cookie_auth 容错瞬时跳转,避免间歇性误判失效
This commit is contained in:
@@ -49,8 +49,10 @@ def _build_login_result(success: bool, status: str, message: str, account_file:
|
|||||||
|
|
||||||
|
|
||||||
async def cookie_auth(account_file):
|
async def cookie_auth(account_file):
|
||||||
async with async_playwright() as playwright:
|
|
||||||
# 抖音无头会撞反爬墙→content/upload 跳登录→误判 cookie 失效(间歇性)。校验必须有头。
|
# 抖音无头会撞反爬墙→content/upload 跳登录→误判 cookie 失效(间歇性)。校验必须有头。
|
||||||
|
# 即便有头,页面慢/瞬时跳转仍会让 wait_for_url(精确URL,5s) 误判→重试3次+宽松判定(URL含 content/upload 且无登录文案)。
|
||||||
|
for _attempt in range(3):
|
||||||
|
async with async_playwright() as playwright:
|
||||||
browser = await playwright.chromium.launch(
|
browser = await playwright.chromium.launch(
|
||||||
headless=False, channel="chrome",
|
headless=False, channel="chrome",
|
||||||
args=["--no-sandbox", "--disable-blink-features=AutomationControlled"],
|
args=["--no-sandbox", "--disable-blink-features=AutomationControlled"],
|
||||||
@@ -60,17 +62,15 @@ async def cookie_auth(account_file):
|
|||||||
context = await set_init_script(context)
|
context = await set_init_script(context)
|
||||||
page = await context.new_page()
|
page = await context.new_page()
|
||||||
await page.goto("https://creator.douyin.com/creator-micro/content/upload", wait_until="domcontentloaded", timeout=90000)
|
await page.goto("https://creator.douyin.com/creator-micro/content/upload", wait_until="domcontentloaded", timeout=90000)
|
||||||
try:
|
await page.wait_for_timeout(2500) # 等页面稳定,避免瞬时跳转误判
|
||||||
await page.wait_for_url("https://creator.douyin.com/creator-micro/content/upload", timeout=5000)
|
has_login = await page.get_by_text("手机号登录").count() or await page.get_by_text("扫码登录").count()
|
||||||
except Exception:
|
if "content/upload" in page.url and not has_login:
|
||||||
return False
|
|
||||||
|
|
||||||
if await page.get_by_text("手机号登录").count() or await page.get_by_text("扫码登录").count():
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
finally:
|
finally:
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def douyin_setup(account_file, handle=False, return_detail=False, qrcode_callback=None, headless: bool = LOCAL_CHROME_HEADLESS):
|
async def douyin_setup(account_file, handle=False, return_detail=False, qrcode_callback=None, headless: bool = LOCAL_CHROME_HEADLESS):
|
||||||
|
|||||||
Reference in New Issue
Block a user