diff --git a/myUtils/auth.py b/myUtils/auth.py index 013f0ef..ea10093 100644 --- a/myUtils/auth.py +++ b/myUtils/auth.py @@ -22,18 +22,21 @@ async def cookie_auth_douyin(account_file): await page.goto("https://creator.douyin.com/creator-micro/content/upload") try: await page.wait_for_url("https://creator.douyin.com/creator-micro/content/upload", timeout=5000) + # 2024.06.17 抖音创作者中心改版 + # 判断 + # 等待“扫码登录”元素出现,超时 5 秒(如果 5 秒没出现,说明 cookie 有效) + try: + await page.get_by_text("扫码登录").wait_for(timeout=5000) + logger.error("[+] cookie 失效,需要扫码登录") + return False + except: + logger.success("[+] cookie 有效") + return True except: - print("[+] 等待5秒 cookie 失效") + logger.error("[+] 等待5秒 cookie 失效") await context.close() await browser.close() return False - # 2024.06.17 抖音创作者中心改版 - if await page.get_by_text('手机号登录').count() or await page.get_by_text('扫码登录').count(): - print("[+] 等待5秒 cookie 失效") - return False - else: - print("[+] cookie 有效") - return True async def cookie_auth_tencent(account_file): async with async_playwright() as playwright: @@ -114,4 +117,4 @@ async def check_cookie(type,file_path): return False # a = asyncio.run(check_cookie(1,"3a6cfdc0-3d51-11f0-8507-44e51723d63c.json")) -# print(a) \ No newline at end of file +# print(a)