diff --git a/report_video.py b/report_video.py index 494ae49..a80a5c0 100644 --- a/report_video.py +++ b/report_video.py @@ -305,38 +305,53 @@ class DailymotionClient: @require_login def report_follow_up(self, report_id: str): - max_retries = 3 # 最大重试次数 - retry_delay = 2 # 重试间隔(秒) + max_retries = 3 + retry_delay = 2 loaded = False subsequent_status = "" - # 重试页面加载和状态检测 + for attempt in range(max_retries): try: self.page.goto(f"https://faq.dailymotion.com/hc/en-us/requests/{report_id}", timeout=30000) + self.page.wait_for_load_state("networkidle") # 保证页面加载稳定 self.page.wait_for_selector("span.status-label", timeout=30000) - status_raw = self.page.locator("span.status-label").text_content() + try: + status_raw = self.page.locator("span.status-label").text_content() + except Exception as e: + print(f"[警告] 获取状态标签失败: {e}") + status_raw = None + subsequent_status = status_raw.strip().lower() if status_raw else None loaded = True - break # 成功则跳出循环 + break except Exception as e: - print(f"尝试 {attempt + 1}/{max_retries} 失败: {str(e)}") + print(f"[ERROR] 尝试 {attempt + 1}/{max_retries} 失败: {e}") if attempt < max_retries - 1: time.sleep(retry_delay) if not loaded: return 1, "页面加载失败" - txt = "I am the authorized agent of Beijing iQIYI Technology Co., Ltd., responsible for dealing with unauthorized overseas distribution of pirated videos of our works.We have confirmed that the above links contain infringing content and we insist on requesting to takedown. Thank you!" + + txt = ( + "I am the authorized agent of Beijing iQIYI Technology Co., Ltd., responsible for dealing with " + "unauthorized overseas distribution of pirated videos of our works. " + "We have confirmed that the above links contain infringing content and we insist on requesting to takedown. Thank you!" + ) if "awaiting your reply" in subsequent_status: span_show = self.page.locator('span.comment-show-container-content') if span_show.count() > 0: span_show.nth(0).click() self.page.wait_for_timeout(1000) + textarea = self.page.locator('#request_comment_body') textarea.type(txt, delay=30) self.page.wait_for_timeout(1000) self.page.get_by_role("button", name="Submit").click() - self.page.wait_for_selector("span.status-label", timeout=30000) + + success = self.wait_for_selector_safe("span.status-label", timeout=30000, retries=3) + if not success: + return 1, "提交后未检测到状态更新" span_show = self.page.locator('span.comment-show-container-content') if span_show.count() > 0: @@ -346,12 +361,23 @@ class DailymotionClient: return 1, pic_path elif "open" in subsequent_status: - return 1,"" - # 处理 Open 状态 + return 1, "" elif "solved" in subsequent_status: -# 处理 Solved 状态 - return 2,"" + return 2, "" + + return 0, "未知状态" + + def wait_for_selector_safe(self, selector: str, timeout=30000, retries=3, retry_delay=2): + for i in range(retries): + try: + self.page.wait_for_selector(selector, timeout=timeout) + return True + except Exception as e: + print(f"[重试] 第 {i + 1}/{retries} 次等待 {selector} 失败: {e}") + if i < retries - 1: + time.sleep(retry_delay) + return False @require_login def test(self):