fix:粗糙修复,兼容两种跳转页面
This commit is contained in:
+1
-1
@@ -159,7 +159,7 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
.idea/
|
||||
|
||||
|
||||
.DS_Store
|
||||
|
||||
# ignore cookie file
|
||||
tencent_uploader/*.json
|
||||
|
||||
@@ -115,23 +115,32 @@ class DouYinVideo(object):
|
||||
# 点击 "上传视频" 按钮
|
||||
await page.locator("div[class^='container'] input").set_input_files(self.file_path)
|
||||
|
||||
# 等待页面跳转到指定的 URL
|
||||
# 等待页面跳转到指定的 URL 2025.01.08修改在原有基础上兼容两种页面
|
||||
while True:
|
||||
# 判断是是否进入视频发布页面,没进入,则自动等待到超时
|
||||
try:
|
||||
# 尝试等待第一个 URL
|
||||
await page.wait_for_url(
|
||||
"https://creator.douyin.com/creator-micro/content/post/video?enter_from=publish_page")
|
||||
break
|
||||
except:
|
||||
douyin_logger.info(f' [-] 正在等待进入视频发布页面...')
|
||||
await asyncio.sleep(0.1)
|
||||
"https://creator.douyin.com/creator-micro/content/publish?enter_from=publish_page", timeout=3)
|
||||
douyin_logger.info("[+] 成功进入version_1发布页面!")
|
||||
break # 成功进入页面后跳出循环
|
||||
except Exception:
|
||||
try:
|
||||
# 如果第一个 URL 超时,再尝试等待第二个 URL
|
||||
await page.wait_for_url(
|
||||
"https://creator.douyin.com/creator-micro/content/post/video?enter_from=publish_page",
|
||||
timeout=3)
|
||||
douyin_logger.info("[+] 成功进入version_2发布页面!")
|
||||
|
||||
break # 成功进入页面后跳出循环
|
||||
except:
|
||||
print(" [-] 超时未进入视频发布页面,重新尝试...")
|
||||
await asyncio.sleep(0.5) # 等待 0.5 秒后重新尝试
|
||||
# 填充标题和话题
|
||||
# 检查是否存在包含输入框的元素
|
||||
# 这里为了避免页面变化,故使用相对位置定位:作品标题父级右侧第一个元素的input子元素
|
||||
await asyncio.sleep(1)
|
||||
douyin_logger.info(f' [-] 正在填充标题和话题...')
|
||||
title_container = page.get_by_placeholder('作品标题')
|
||||
title_container = page.get_by_text('作品标题').locator("..").locator("xpath=following-sibling::div[1]").locator("input")
|
||||
if await title_container.count():
|
||||
await title_container.fill(self.title[:30])
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user