This commit is contained in:
zk
2026-07-27 15:53:47 +08:00
parent 4a068ede59
commit 6e70258208
2 changed files with 243 additions and 182 deletions
+6 -1
View File
@@ -13,7 +13,7 @@
from __future__ import annotations
from app.core.logger import log
from app.tool.browser import open_page, query
from app.tool.browser import close_page, open_page, query
from app.tool.cv import has_qr
from app.tool.image_download import download_image
from app.tool.ocr import ocr
@@ -39,12 +39,17 @@ def extract_page(url: str) -> str:
if not url or not url.startswith("http"):
return ""
page_id: str | None = None
try:
page_id = open_page(url, _WAIT_MS)
nodes = query(page_id, _SELECTOR)
except Exception as exc:
log.error(f"公告页打开失败: {url} | {exc}")
return ""
finally:
# 页面数据已取出,尽早释放浏览器上下文,不占着资源等后续 OCR
if page_id is not None:
close_page(page_id)
texts: list[str] = []
image_urls: list[str] = []