home@pookz.com commited on
Commit
e8a1160
·
1 Parent(s): 659bb95

fix:粗糙修复,兼容两种跳转页面

Browse files
Files changed (2) hide show
  1. .gitignore +1 -1
  2. uploader/douyin_uploader/main.py +18 -9
.gitignore CHANGED
@@ -159,7 +159,7 @@ cython_debug/
159
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
  .idea/
161
 
162
-
163
 
164
  # ignore cookie file
165
  tencent_uploader/*.json
 
159
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
  .idea/
161
 
162
+ .DS_Store
163
 
164
  # ignore cookie file
165
  tencent_uploader/*.json
uploader/douyin_uploader/main.py CHANGED
@@ -115,23 +115,32 @@ class DouYinVideo(object):
115
  # 点击 "上传视频" 按钮
116
  await page.locator("div[class^='container'] input").set_input_files(self.file_path)
117
 
118
- # 等待页面跳转到指定的 URL
119
  while True:
120
- # 判断是是否进入视频发布页面,没进入,则自动等待到超时
121
  try:
 
122
  await page.wait_for_url(
123
- "https://creator.douyin.com/creator-micro/content/post/video?enter_from=publish_page")
124
- break
125
- except:
126
- douyin_logger.info(f' [-] 正在等待进入视频发布页面...')
127
- await asyncio.sleep(0.1)
128
-
 
 
 
 
 
 
 
 
 
129
  # 填充标题和话题
130
  # 检查是否存在包含输入框的元素
131
  # 这里为了避免页面变化,故使用相对位置定位:作品标题父级右侧第一个元素的input子元素
132
  await asyncio.sleep(1)
133
  douyin_logger.info(f' [-] 正在填充标题和话题...')
134
- title_container = page.get_by_placeholder('作品标题')
135
  if await title_container.count():
136
  await title_container.fill(self.title[:30])
137
  else:
 
115
  # 点击 "上传视频" 按钮
116
  await page.locator("div[class^='container'] input").set_input_files(self.file_path)
117
 
118
+ # 等待页面跳转到指定的 URL 2025.01.08修改在原有基础上兼容两种页面
119
  while True:
 
120
  try:
121
+ # 尝试等待第一个 URL
122
  await page.wait_for_url(
123
+ "https://creator.douyin.com/creator-micro/content/publish?enter_from=publish_page", timeout=3)
124
+ douyin_logger.info("[+] 成功进入version_1发布页面!")
125
+ break # 成功进入页面后跳出循环
126
+ except Exception:
127
+ try:
128
+ # 如果第一个 URL 超时,再尝试等待第二个 URL
129
+ await page.wait_for_url(
130
+ "https://creator.douyin.com/creator-micro/content/post/video?enter_from=publish_page",
131
+ timeout=3)
132
+ douyin_logger.info("[+] 成功进入version_2发布页面!")
133
+
134
+ break # 成功进入页面后跳出循环
135
+ except:
136
+ print(" [-] 超时未进入视频发布页面,重新尝试...")
137
+ await asyncio.sleep(0.5) # 等待 0.5 秒后重新尝试
138
  # 填充标题和话题
139
  # 检查是否存在包含输入框的元素
140
  # 这里为了避免页面变化,故使用相对位置定位:作品标题父级右侧第一个元素的input子元素
141
  await asyncio.sleep(1)
142
  douyin_logger.info(f' [-] 正在填充标题和话题...')
143
+ title_container = page.get_by_text('作品标题').locator("..").locator("xpath=following-sibling::div[1]").locator("input")
144
  if await title_container.count():
145
  await title_container.fill(self.title[:30])
146
  else: