From 6e9298fd7fcc5a136c28740360be8c8cee5af430 Mon Sep 17 00:00:00 2001 From: "home@pookz.com" Date: Wed, 8 Jan 2025 11:09:46 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E7=B2=97=E7=B3=99=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=8C=E5=85=BC=E5=AE=B9=E4=B8=A4=E7=A7=8D=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- uploader/douyin_uploader/main.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 41288b9..471dea8 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/uploader/douyin_uploader/main.py b/uploader/douyin_uploader/main.py index 9737b98..6ac8582 100644 --- a/uploader/douyin_uploader/main.py +++ b/uploader/douyin_uploader/main.py @@ -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: