From 51209a133183616f31e4bc86424934b7d30e812f Mon Sep 17 00:00:00 2001 From: changyandaoc Date: Sun, 14 Jun 2026 07:15:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(douyin):=20cookie=5Fauth=20=E9=97=B4?= =?UTF-8?q?=E6=AD=87=E6=80=A7=E8=AF=AF=E5=88=A4=E5=A4=B1=E6=95=88=E2=80=94?= =?UTF-8?q?=E2=80=94=E9=87=8D=E8=AF=953=E6=AC=A1+=E5=AE=BD=E6=9D=BE?= =?UTF-8?q?=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有头校验仍会因页面慢/瞬时跳转让 wait_for_url(精确URL,5s) 超时误判, 导致 check 通过但 upload 前置校验失败。改为重试3次 + 等2.5s稳定 + 宽松判定(URL含 content/upload 且无登录文案)。 --- uploader/douyin_uploader/main.py | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/uploader/douyin_uploader/main.py b/uploader/douyin_uploader/main.py index 5a76a3c..c82adbf 100644 --- a/uploader/douyin_uploader/main.py +++ b/uploader/douyin_uploader/main.py @@ -49,28 +49,28 @@ def _build_login_result(success: bool, status: str, message: str, account_file: async def cookie_auth(account_file): - async with async_playwright() as playwright: - # 抖音无头会撞反爬墙→content/upload 跳登录→误判 cookie 失效(间歇性)。校验必须有头。 - browser = await playwright.chromium.launch( - headless=False, channel="chrome", - args=["--no-sandbox", "--disable-blink-features=AutomationControlled"], - ) - try: - context = await browser.new_context(storage_state=account_file) - context = await set_init_script(context) - page = await context.new_page() - await page.goto("https://creator.douyin.com/creator-micro/content/upload", wait_until="domcontentloaded", timeout=90000) + # 抖音无头会撞反爬墙→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( + headless=False, channel="chrome", + args=["--no-sandbox", "--disable-blink-features=AutomationControlled"], + ) try: - await page.wait_for_url("https://creator.douyin.com/creator-micro/content/upload", timeout=5000) + context = await browser.new_context(storage_state=account_file) + context = await set_init_script(context) + page = await context.new_page() + await page.goto("https://creator.douyin.com/creator-micro/content/upload", wait_until="domcontentloaded", timeout=90000) + await page.wait_for_timeout(2500) # 等页面稳定,避免瞬时跳转误判 + has_login = await page.get_by_text("手机号登录").count() or await page.get_by_text("扫码登录").count() + if "content/upload" in page.url and not has_login: + return True except Exception: - return False - - if await page.get_by_text("手机号登录").count() or await page.get_by_text("扫码登录").count(): - return False - - return True - finally: - await browser.close() + pass + finally: + await browser.close() + return False async def douyin_setup(account_file, handle=False, return_detail=False, qrcode_callback=None, headless: bool = LOCAL_CHROME_HEADLESS):