陶欣 commited on
Commit
56146fe
·
1 Parent(s): a4809e4

修复抖音cookie有效性判定

Browse files
Files changed (1) hide show
  1. myUtils/auth.py +12 -9
myUtils/auth.py CHANGED
@@ -22,18 +22,21 @@ async def cookie_auth_douyin(account_file):
22
  await page.goto("https://creator.douyin.com/creator-micro/content/upload")
23
  try:
24
  await page.wait_for_url("https://creator.douyin.com/creator-micro/content/upload", timeout=5000)
 
 
 
 
 
 
 
 
 
 
25
  except:
26
- print("[+] 等待5秒 cookie 失效")
27
  await context.close()
28
  await browser.close()
29
  return False
30
- # 2024.06.17 抖音创作者中心改版
31
- if await page.get_by_text('手机号登录').count() or await page.get_by_text('扫码登录').count():
32
- print("[+] 等待5秒 cookie 失效")
33
- return False
34
- else:
35
- print("[+] cookie 有效")
36
- return True
37
 
38
  async def cookie_auth_tencent(account_file):
39
  async with async_playwright() as playwright:
@@ -114,4 +117,4 @@ async def check_cookie(type,file_path):
114
  return False
115
 
116
  # a = asyncio.run(check_cookie(1,"3a6cfdc0-3d51-11f0-8507-44e51723d63c.json"))
117
- # print(a)
 
22
  await page.goto("https://creator.douyin.com/creator-micro/content/upload")
23
  try:
24
  await page.wait_for_url("https://creator.douyin.com/creator-micro/content/upload", timeout=5000)
25
+ # 2024.06.17 抖音创作者中心改版
26
+ # 判断
27
+ # 等待“扫码登录”元素出现,超时 5 秒(如果 5 秒没出现,说明 cookie 有效)
28
+ try:
29
+ await page.get_by_text("扫码登录").wait_for(timeout=5000)
30
+ logger.error("[+] cookie 失效,需要扫码登录")
31
+ return False
32
+ except:
33
+ logger.success("[+] cookie 有效")
34
+ return True
35
  except:
36
+ logger.error("[+] 等待5秒 cookie 失效")
37
  await context.close()
38
  await browser.close()
39
  return False
 
 
 
 
 
 
 
40
 
41
  async def cookie_auth_tencent(account_file):
42
  async with async_playwright() as playwright:
 
117
  return False
118
 
119
  # a = asyncio.run(check_cookie(1,"3a6cfdc0-3d51-11f0-8507-44e51723d63c.json"))
120
+ # print(a)