使用js去强制点击视频

This commit is contained in:
Your Name
2025-08-21 21:58:07 +08:00
parent cac31a29e0
commit a309d0b034
2 changed files with 15 additions and 39 deletions

View File

@@ -25,7 +25,6 @@ from exceptions import AuthException, OperationFailed
from miniofile import client, put_object
def sleep(a, b=None):
if not b:
return time.sleep(a)
@@ -276,18 +275,19 @@ def retry_get_new_video(page, cookies, post_count):
# 如果新帖子数量大于初始帖子数量,则表示有新帖子上传
if new_post_count > post_count:
try:
# 尝试点击评论按钮
# 尝试点击视频
comment_buttons = page.query_selector_all(
'//a[@aria-label="Enlarge"]')
if comment_buttons:
comment_buttons[0].hover()
comment_buttons[0].click()
# 使用js去点击第一个评论按钮
element = page.query_selector_all('//a[@aria-label="Enlarge"]')[0]
page.evaluate('(element) => element.click()', element)
time.sleep(random.randint(3, 5))
page.reload()
time.sleep(random.randint(3, 5))
return page.url
except Exception as e:
raise OperationFailed(f"点击评论按钮时出错: {e}")
raise OperationFailed(f"点击视频时出错: {e}")
# 计算下一次重试时间
elapsed = time.time() - start_time