This commit is contained in:
HuangHai
2026-01-13 19:00:56 +08:00
parent 88ed668b7d
commit 0d4f892ead
7 changed files with 37 additions and 72 deletions

View File

@@ -4,7 +4,7 @@
# 调大步长 (从 0.25 调至 0.5),提高采集效率 # 调大步长 (从 0.25 调至 0.5),提高采集效率
SCROLL_DISTANCE_RATIO = 0.5 SCROLL_DISTANCE_RATIO = 0.5
# 最大滑动/翻页次数,达到此次数后停止采集 # 最大滑动/翻页次数,达到此次数后停止采集
MAX_SCROLLS = 60 MAX_SCROLLS = 100
# 默认抓取半径(公里),当检测到场站距离超过此值时停止采集 # 默认抓取半径(公里),当检测到场站距离超过此值时停止采集
MAX_CRAWL_DISTANCE = 50 MAX_CRAWL_DISTANCE = 50
# 场站去重过期时间(秒),在此时间内重复出现的场站不会再次点击进入详情页 # 场站去重过期时间(秒),在此时间内重复出现的场站不会再次点击进入详情页

View File

@@ -164,36 +164,9 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
image_uuid = str(uuid.uuid4()) image_uuid = str(uuid.uuid4())
screenshot_path = take_screenshot(d, image_uuid, save_dir=TEMP_IMAGE_DIR) screenshot_path = take_screenshot(d, image_uuid, save_dir=TEMP_IMAGE_DIR)
# 检查是否存在广告 (VL) # 【优化】不再在每页滚动时检查兔子广告,仅在 Opener 进入时检查一次
logger.info("检查是否存在广告弹窗...") # 如果后续发现有其它非兔子广告弹出,可在此处恢复非兔子广告的检测逻辑
ad_res = await ReadImageKit.detect_ad_popup(screenshot_path, device_info=device_info) ad_top_y_norm = 0.78 # 默认的点击边界 (0.78)
ad_top_y_norm = 0.78 # 恢复默认的点击边界 (0.78),不再需要为了避开兔子而设为 0.90
if ad_res:
ad_type = ad_res.get("ad_type")
if ad_type == "rabbit":
logger.info(">>> 检测到兔子广告。尝试使用图片识别关闭...")
try:
# 使用基于图片的关闭方案
template_path = os.path.join(os.path.dirname(__file__), "Template", "X.jpg")
if d.image.click(template_path, timeout=3.0):
logger.info(">>> 成功通过图片识别关闭兔子广告。")
await asyncio.sleep(1.5)
# 重新截图,因为广告已关闭
if os.path.exists(screenshot_path): os.remove(screenshot_path)
screenshot_path = take_screenshot(d, image_uuid, save_dir=TEMP_IMAGE_DIR)
else:
logger.warning(">>> 图片识别未找到兔子广告关闭按钮。")
except Exception as ex:
logger.error(f">>> 图片识别关闭兔子广告异常: {ex}")
else:
x, y = ad_res['x'], ad_res['y']
logger.info(f"检测到非兔子广告: {ad_res} [Type: {ad_type}],正在关闭...")
d.click(x, y)
await asyncio.sleep(1.5)
# 重新截图
if os.path.exists(screenshot_path): os.remove(screenshot_path)
screenshot_path = take_screenshot(d, image_uuid, save_dir=TEMP_IMAGE_DIR)
# 检查是否已经滚动到底部 (排除状态栏后,内容与上次一致) # 检查是否已经滚动到底部 (排除状态栏后,内容与上次一致)
current_md5 = Kit.get_image_content_md5( current_md5 = Kit.get_image_content_md5(
@@ -275,32 +248,10 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
detail_path = take_screenshot(d, detail_uuid, save_dir=TEMP_IMAGE_DIR) detail_path = take_screenshot(d, detail_uuid, save_dir=TEMP_IMAGE_DIR)
# 【新增】二级页面广告检测 (如:免费停车提示) # 【新增】二级页面广告检测 (如:免费停车提示)
logger.info("检查详情页是否存在干扰弹窗...") # 【优化】不再在详情页检查广告,节省时间和 Token
detail_ad_res = await ReadImageKit.detect_ad_popup(detail_path, device_info=device_info) # detail_ad_res = await ReadImageKit.detect_ad_popup(detail_path, device_info=device_info)
if detail_ad_res: # if detail_ad_res:
dad_type = detail_ad_res.get("ad_type") # ... (代码已移除)
if dad_type == "rabbit":
logger.info(">>> 详情页检测到 rabbit 广告。尝试使用图片识别关闭...")
try:
template_path = os.path.join(os.path.dirname(__file__), "Template", "X.jpg")
if d.image.click(template_path, timeout=3.0):
logger.info(">>> 详情页成功通过图片识别关闭兔子广告。")
await asyncio.sleep(1.5)
# 重新截图
if os.path.exists(detail_path): os.remove(detail_path)
detail_path = take_screenshot(d, detail_uuid, save_dir=TEMP_IMAGE_DIR)
else:
logger.warning(">>> 详情页图片识别未找到兔子广告关闭按钮,跳过。")
except Exception as ex:
logger.error(f">>> 详情页图片识别关闭兔子广告异常: {ex}")
else:
dx, dy = detail_ad_res["x"], detail_ad_res["y"]
logger.info(f"检测到详情页弹窗: {dad_type},正在点击关闭 ({dx}, {dy})...")
d.click(dx, dy)
await asyncio.sleep(1.5)
# 重新截图,确保后续流程使用的是清理后的界面
if os.path.exists(detail_path): os.remove(detail_path)
detail_path = take_screenshot(d, detail_uuid, save_dir=TEMP_IMAGE_DIR)
# 【优化】后台解析详情页地址,直接传本地路径,避免等待上传 # 【优化】后台解析详情页地址,直接传本地路径,避免等待上传
logger.info(f"已启动后台分析详情页: {station_name}") logger.info(f"已启动后台分析详情页: {station_name}")
@@ -326,11 +277,25 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
# 1. 尝试模板匹配 # 1. 尝试模板匹配
match_res = d.image.match(template_qbsd) match_res = d.image.match(template_qbsd)
if match_res: if match_res:
click_pos = (match_res['x'], match_res['y']) # 兼容 uiautomator2 不同版本的返回结果 (Match对象或dict)
logger.info(f"通过 qbsd.jpg成功找到!坐标: {click_pos}") if hasattr(match_res, 'point') and match_res.point:
else: click_pos = match_res.point
# 2. 模板匹配失败,降级为 VL 识别 elif isinstance(match_res, dict):
logger.info("qbsd.jpg 匹配失败,降级使用 VL 识别...") if 'point' in match_res and match_res['point']:
click_pos = match_res['point']
elif 'x' in match_res and 'y' in match_res:
click_pos = (match_res['x'], match_res['y'])
elif isinstance(match_res, (list, tuple)) and len(match_res) >= 2:
click_pos = (match_res[0], match_res[1])
if click_pos:
logger.info(f"通过 qbsd.jpg 成功找到!坐标: {click_pos}")
else:
logger.warning(f"模板匹配成功但无法解析坐标: {match_res}")
# 如果模板匹配未成功解析坐标,或者匹配直接失败,则降级到 VL
if not click_pos:
logger.info("模板匹配未找到或解析失败,降级使用 VL 识别...")
res = await ReadImageKit.find_all_time_button_coordinate(detail_path, device_info=device_info) res = await ReadImageKit.find_all_time_button_coordinate(detail_path, device_info=device_info)
if res.get("uia_center_x"): if res.get("uia_center_x"):
click_pos = (res.get("uia_center_x"), res.get("uia_center_y")) click_pos = (res.get("uia_center_x"), res.get("uia_center_y"))

View File

@@ -1,16 +1,16 @@
# 黄海在公司内网开发时的配置信息 # 黄海在公司内网开发时的配置信息
DORIS_HOST = "10.10.14.204" # DORIS_HOST = "10.10.14.204"
DORIS_PORT = 9030 # DORIS_PORT = 9030
DORIS_FENODES = "10.10.14.204:8030" # DORIS_FENODES = "10.10.14.204:8030"
REDIS_HOST = '10.10.14.14' # REDIS_HOST = '10.10.14.14'
REDIS_PASSWORD = None # 如果没有密码则设为 None # REDIS_PASSWORD = None # 如果没有密码则设为 None
# 黄海在家开发时的配置信息 # 黄海在家开发时的配置信息
# DORIS_HOST = "www.hzkjai.com" DORIS_HOST = "www.hzkjai.com"
# DORIS_PORT = 27025 DORIS_PORT = 27025
# DORIS_FENODES = "www.hzkjai.com:27024" DORIS_FENODES = "www.hzkjai.com:27024"
# REDIS_HOST = '127.0.0.1' REDIS_HOST = '127.0.0.1'
# REDIS_PASSWORD = "DsideaL147258369" REDIS_PASSWORD = "DsideaL147258369"
# 视觉模型配置 # 视觉模型配置
VL_MODEL_NAME = "qwen3-vl-flash" VL_MODEL_NAME = "qwen3-vl-flash"