This commit is contained in:
HuangHai
2026-01-14 16:28:22 +08:00
parent 27a81f5ce2
commit a3fd56c5cd
4 changed files with 25 additions and 59 deletions

View File

@@ -241,59 +241,16 @@ class TeLaiDianCrawler(BaseCrawler):
d.swipe(w * 0.5, h * 0.8, w * 0.5, h * 0.3, 0.5)
await asyncio.sleep(1.0)
template_jgxx = os.path.join(os.path.dirname(__file__), "Template", "jgxx.jpg")
template_qbsd = os.path.join(os.path.dirname(__file__), "Template", "qbsd.jpg")
entrance_point = None
entrance_source = None
max_search_rounds = 5
if os.path.exists(template_qbsd):
try:
match_res_qbsd = d.image.match(template_qbsd)
except Exception as e:
match_res_qbsd = None
logger.error(f"[详情页] qbsd 模板匹配价格入口失败: {e}")
if match_res_qbsd:
logger.info(f"[详情页] qbsd 模板匹配返回结果: {match_res_qbsd}")
if hasattr(match_res_qbsd, "point") and match_res_qbsd.point:
entrance_point = match_res_qbsd.point
elif isinstance(match_res_qbsd, dict):
if "point" in match_res_qbsd and match_res_qbsd["point"]:
entrance_point = match_res_qbsd["point"]
elif "x" in match_res_qbsd and "y" in match_res_qbsd:
entrance_point = (match_res_qbsd["x"], match_res_qbsd["y"])
elif isinstance(match_res_qbsd, (list, tuple)) and len(match_res_qbsd) >= 2:
entrance_point = (match_res_qbsd[0], match_res_qbsd[1])
if entrance_point:
entrance_source = "qbsd"
logger.info(f"[详情页] 通过 qbsd.jpg 成功找到价格入口: {entrance_point}")
for round_idx in range(max_search_rounds):
if entrance_point:
break
search_screen_path = take_screenshot(d, f"tld_detail_search_{int(time.time())}_{round_idx}.jpg")
logger.info(f"[详情页] 搜索价格入口,第 {round_idx + 1}/{max_search_rounds} 轮: {search_screen_path}")
if os.path.exists(template_jgxx):
try:
match_res = d.image.match(template_jgxx)
except Exception as e:
match_res = None
logger.error(f"[详情页] 模板匹配价格入口失败: {e}")
if match_res:
logger.info(f"[详情页] 模板匹配返回结果: {match_res}")
if hasattr(match_res, "point") and match_res.point:
entrance_point = match_res.point
elif isinstance(match_res, dict):
if "point" in match_res and match_res["point"]:
entrance_point = match_res["point"]
elif "x" in match_res and "y" in match_res:
entrance_point = (match_res["x"], match_res["y"])
elif isinstance(match_res, (list, tuple)) and len(match_res) >= 2:
entrance_point = (match_res[0], match_res[1])
if entrance_point and not entrance_source:
entrance_source = "jgxx"
if not entrance_point:
try:
vlm_res = await self.read_image_kit.find_price_entrance_vlm(search_screen_path)
@@ -332,10 +289,17 @@ class TeLaiDianCrawler(BaseCrawler):
)
ex, ey = int(entrance_point[0]), int(entrance_point[1])
click_x = ex
offset_y = int(h * 0.1)
click_y = min(h - 10, ey + offset_y)
logger.info(f"[详情页] 使用 {entrance_source or '模板'} 价格入口坐标: ({ex}, {ey}),调整后点击坐标: ({click_x}, {click_y}),即将进入电价页")
entered_price_page = False
if entrance_source == "vlm":
click_x = ex
click_y = ey
logger.info(f"[详情页] 使用 VLM 当前价红色价格入口坐标直接点击: ({click_x}, {click_y})")
else:
click_x = ex
offset_y = int(h * 0.1)
click_y = min(h - 10, ey + offset_y)
logger.info(f"[详情页] 使用 {entrance_source or '入口'} 坐标: ({ex}, {ey}),调整后点击坐标: ({click_x}, {click_y}),即将进入电价页")
d.click(click_x, click_y)
await asyncio.sleep(WAIT_DETAIL_PAGE_LOAD)
@@ -346,13 +310,11 @@ class TeLaiDianCrawler(BaseCrawler):
bottom_ratio=BOTTOM_SAFE_EXCLUDE_RATIO,
)
entered_price_page = False
if before_md5 and after_md5 and before_md5 != after_md5:
entered_price_page = True
logger.info("[电价页] 模板点击后页面内容发生变化,判定已进入电价详情页。")
logger.info("[电价页] 首次点击后页面内容发生变化,判定已进入电价详情页。")
else:
logger.warning("[电价页] 模板点击后页面内容无明显变化,尝试使用 VLM 兜底寻找价格入口。")
logger.warning("[电价页] 首次点击后页面内容无明显变化,尝试使用 VLM 兜底寻找价格入口。")
try:
vlm_res = await self.read_image_kit.find_price_entrance_vlm(before_price_path)
except Exception as e:
@@ -371,7 +333,7 @@ class TeLaiDianCrawler(BaseCrawler):
logger.info(f"[电价页] 使用 VLM 兜底点击价格入口: ({vx}, {vy}),原因: {vlm_res.get('reason')}")
d.click(vx, vy)
await asyncio.sleep(WAIT_DETAIL_PAGE_LOAD)
vlm_after_path = take_screenshot(d, f"tld_detail_price_after_vlm_{int(time.time())}.jpg")
vlm_after_md5 = get_image_content_md5(
vlm_after_path,