'commit'
This commit is contained in:
@@ -313,17 +313,31 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
|
|||||||
loop.run_in_executor(None, uploader.upload_file, detail_object_key, detail_path)
|
loop.run_in_executor(None, uploader.upload_file, detail_object_key, detail_path)
|
||||||
|
|
||||||
# --- 抓取价格时段信息 ---
|
# --- 抓取价格时段信息 ---
|
||||||
# 【优化】使用模板匹配点击 "全部时段" 按钮,节省 VL Token 且更稳定
|
# 【优化】梯级识别策略:优先模板匹配 (qbsd.jpg),失败则降级为 VL 识别
|
||||||
template_qbsd = os.path.join(os.path.dirname(__file__), "Template", "qbsd.jpg")
|
template_qbsd = os.path.join(os.path.dirname(__file__), "Template", "qbsd.jpg")
|
||||||
logger.info(f"尝试通过图片识别点击 '全部时段' 按钮: {template_qbsd}")
|
|
||||||
|
|
||||||
# 记录点击前的页面特征,用于验证是否成功进入三级页面
|
# 记录点击前的页面特征,用于验证是否成功进入三级页面
|
||||||
before_click_md5 = Kit.get_image_content_md5(detail_path)
|
before_click_md5 = Kit.get_image_content_md5(detail_path)
|
||||||
|
|
||||||
entered_price_page = False
|
entered_price_page = False
|
||||||
|
click_pos = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if d.image.click(template_qbsd, timeout=5.0):
|
# 1. 尝试模板匹配
|
||||||
logger.info("成功通过图片识别点击 '全部时段' 按钮")
|
match_res = d.image.match(template_qbsd)
|
||||||
|
if match_res:
|
||||||
|
click_pos = (match_res['x'], match_res['y'])
|
||||||
|
logger.info(f"通过 qbsd.jpg成功找到!坐标: {click_pos}")
|
||||||
|
else:
|
||||||
|
# 2. 模板匹配失败,降级为 VL 识别
|
||||||
|
logger.info("qbsd.jpg 匹配失败,降级使用 VL 识别...")
|
||||||
|
res = await ReadImageKit.find_all_time_button_coordinate(detail_path, device_info=device_info)
|
||||||
|
if res.get("uia_center_x"):
|
||||||
|
click_pos = (res.get("uia_center_x"), res.get("uia_center_y"))
|
||||||
|
logger.info(f"VL 识别成功找到 '全部时段' 按钮: {click_pos}")
|
||||||
|
|
||||||
|
if click_pos:
|
||||||
|
d.click(click_pos[0], click_pos[1])
|
||||||
await asyncio.sleep(1.5)
|
await asyncio.sleep(1.5)
|
||||||
|
|
||||||
# 检查页面是否真的变化了
|
# 检查页面是否真的变化了
|
||||||
@@ -371,14 +385,20 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
|
|||||||
should_back_to_list = True
|
should_back_to_list = True
|
||||||
else:
|
else:
|
||||||
logger.warning(f"返回后状态未知 (ListMD5:{check_list_md5[:8]} vs {current_md5[:8]}, DetailMD5:{check_detail_md5[:8]} vs {before_click_md5[:8]})。")
|
logger.warning(f"返回后状态未知 (ListMD5:{check_list_md5[:8]} vs {current_md5[:8]}, DetailMD5:{check_detail_md5[:8]} vs {before_click_md5[:8]})。")
|
||||||
logger.info("使用图片识别进一步确认当前页面状态...")
|
logger.info("再次尝试识别按钮以确认当前页面状态...")
|
||||||
|
|
||||||
# 使用图片识别检查当前页面是否存在 '全部时段' 按钮
|
# 优先尝试模板匹配确认
|
||||||
if d.image.match(template_qbsd):
|
if d.image.match(template_qbsd):
|
||||||
logger.info("图片识别确认当前仍处于详情页 (发现了'全部时段'按钮),执行返回。")
|
logger.info("模板匹配确认当前仍处于详情页,执行返回。")
|
||||||
should_back_to_list = True
|
should_back_to_list = True
|
||||||
else:
|
else:
|
||||||
logger.info("图片识别未发现'全部时段'按钮,判定已回到列表页(或非详情页),停止回退以防误退。")
|
# 模板匹配未发现,则用 VL 兜底确认
|
||||||
|
check_res = await ReadImageKit.find_all_time_button_coordinate(check_back_path, device_info=device_info)
|
||||||
|
if check_res and check_res.get("uia_center_x"):
|
||||||
|
logger.info("VL 确认当前仍处于详情页,执行返回。")
|
||||||
|
should_back_to_list = True
|
||||||
|
else:
|
||||||
|
logger.info("无法确认当前页面状态,判定已回到列表页(或非详情页),停止回退以防误退。")
|
||||||
should_back_to_list = False
|
should_back_to_list = False
|
||||||
|
|
||||||
# 使用完毕后再清理检查用的截图
|
# 使用完毕后再清理检查用的截图
|
||||||
@@ -390,9 +410,9 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
|
|||||||
# 清理检查用的截图
|
# 清理检查用的截图
|
||||||
if os.path.exists(after_click_path): os.remove(after_click_path)
|
if os.path.exists(after_click_path): os.remove(after_click_path)
|
||||||
else:
|
else:
|
||||||
logger.info(f"场站 {station_name} 通过图片识别未发现 '全部时段' 按钮。")
|
logger.info(f"场站 {station_name} 经过模板匹配与 VL 识别均未发现 '全部时段' 按钮。")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"通过图片识别点击 '全部时段' 按钮异常: {e}")
|
logger.error(f"处理 '全部时段' 按钮点击流程异常: {e}")
|
||||||
|
|
||||||
# 从二级页面返回 (仅当确实需要返回时)
|
# 从二级页面返回 (仅当确实需要返回时)
|
||||||
if should_back_to_list:
|
if should_back_to_list:
|
||||||
|
|||||||
Reference in New Issue
Block a user