From 09188b8765b67f31007a19485453b22cf13b7cc9 Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Wed, 14 Jan 2026 13:14:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=98=B2=E6=AD=A2=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E6=97=B6=E6=97=A0=E9=99=90=E5=BE=AA=E7=8E=AF=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=B7=B2=E5=A4=84=E7=90=86=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 processed_hrefs 集合跟踪已处理的文章 href - 处理文章前检查是否已处理过,避免重复处理 - 添加 new_articles_in_page 计数器,当前页无新文章时退出循环 - 解决 mark_read 未立即生效导致的无限循环问题 Co-Authored-By: Claude Opus 4.5 --- api_browser.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/api_browser.py b/api_browser.py index 5eacf23..de96912 100755 --- a/api_browser.py +++ b/api_browser.py @@ -475,6 +475,7 @@ class APIBrowser: # 这样可以避免分页错位问题(标记已读后文章从列表消失导致后续页面上移) max_iterations = total_records + 10 # 防止无限循环 iteration = 0 + processed_hrefs = set() # 跟踪已处理的文章,防止重复处理 while articles and iteration < max_iterations: iteration += 1 @@ -483,14 +484,24 @@ class APIBrowser: self.log("[API] 收到停止信号") break + new_articles_in_page = 0 # 本次迭代中新处理的文章数 + for article in articles: if should_stop_callback and should_stop_callback(): break + article_href = article['href'] + # 跳过已处理的文章 + if article_href in processed_hrefs: + continue + + processed_hrefs.add(article_href) + new_articles_in_page += 1 title = article['title'][:30] + # 获取附件(文章详情页) try: - attachments = self.get_article_attachments(article['href']) + attachments = self.get_article_attachments(article_href) consecutive_failures = 0 except Exception as e: skipped_items += 1 @@ -514,6 +525,11 @@ class APIBrowser: time.sleep(0.1) + # 如果当前页没有新文章被处理,说明所有文章都已处理过,退出循环 + if new_articles_in_page == 0: + self.log(f"[API] 当前页所有文章均已处理,结束循环") + break + time.sleep(0.2) # 重新获取第1页,检查是否还有未处理的内容