修复发视频帖子
This commit is contained in:
@@ -353,7 +353,7 @@ def get_post_count(page, cookies):
|
|||||||
page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
|
page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
|
||||||
page.wait_for_timeout(random.randint(3, 5) * 1000)
|
page.wait_for_timeout(random.randint(3, 5) * 1000)
|
||||||
# 这里还是获取视频
|
# 这里还是获取视频
|
||||||
posts = page.query_selector_all('//a[@aria-label="Enlarge"]')
|
posts = page.query_selector_all('//div[@aria-label="Video player"]')
|
||||||
# 返回数量
|
# 返回数量
|
||||||
logger.info(f"账号{uid} 获取到帖子数量为{len(posts)}")
|
logger.info(f"账号{uid} 获取到帖子数量为{len(posts)}")
|
||||||
return len(posts)
|
return len(posts)
|
||||||
@@ -371,7 +371,7 @@ def retry_get_new_video(page, cookies, post_count):
|
|||||||
Returns:
|
Returns:
|
||||||
函数执行结果或抛出Timeout(如果超时)
|
函数执行结果或抛出Timeout(如果超时)
|
||||||
"""
|
"""
|
||||||
max_duration = 20 * 60 # 5分钟(秒)
|
max_duration = 10 * 60 # 5分钟(秒)
|
||||||
retry_interval = 30 # 30秒重试一次
|
retry_interval = 30 # 30秒重试一次
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
attempt = 1
|
attempt = 1
|
||||||
@@ -384,10 +384,10 @@ def retry_get_new_video(page, cookies, post_count):
|
|||||||
try:
|
try:
|
||||||
# 尝试点击视频
|
# 尝试点击视频
|
||||||
comment_buttons = page.query_selector_all(
|
comment_buttons = page.query_selector_all(
|
||||||
'//a[@aria-label="Enlarge"]')
|
'//div[@aria-label="Video player"]')
|
||||||
if comment_buttons:
|
if comment_buttons:
|
||||||
# 使用js去点击第一个评论按钮
|
# 使用js去点击第一个评论按钮
|
||||||
element = page.query_selector_all('//a[@aria-label="Enlarge"]')[0]
|
element = page.query_selector_all('//div[@aria-label="Video player"]')[0]
|
||||||
page.evaluate('(element) => element.click()', element)
|
page.evaluate('(element) => element.click()', element)
|
||||||
time.sleep(random.randint(3, 5))
|
time.sleep(random.randint(3, 5))
|
||||||
page.reload()
|
page.reload()
|
||||||
@@ -409,7 +409,7 @@ def retry_get_new_video(page, cookies, post_count):
|
|||||||
attempt += 1
|
attempt += 1
|
||||||
|
|
||||||
print("5分钟超时,退出重试")
|
print("5分钟超时,退出重试")
|
||||||
raise TimeoutError("未获取到新视频(可能视频上传失败),已超时5分钟")
|
raise TimeoutError("未获取到新视频(可能视频上传失败),已超时")
|
||||||
|
|
||||||
|
|
||||||
def playwright_post(cookies, content, image_key=None):
|
def playwright_post(cookies, content, image_key=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user