'commit'
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
# 稍微调大步长 (从 0.15 调至 0.25),兼顾避开广告与采集效率
|
||||
SCROLL_DISTANCE_RATIO = 0.25
|
||||
# 最大滑动/翻页次数,达到此次数后停止采集
|
||||
MAX_SCROLLS = 100
|
||||
MAX_SCROLLS = 60
|
||||
# 默认抓取半径(公里),当检测到场站距离超过此值时停止采集
|
||||
MAX_CRAWL_DISTANCE = 50
|
||||
# 场站去重过期时间(秒),在此时间内重复出现的场站不会再次点击进入详情页
|
||||
|
||||
@@ -168,10 +168,25 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
|
||||
logger.info("检查是否存在广告弹窗...")
|
||||
ad_res = await ReadImageKit.detect_ad_popup(screenshot_path, device_info=device_info)
|
||||
|
||||
ad_top_y_norm = 0.90 # 默认使用一个更宽松的底部边界 (0.90),防止点到导航栏
|
||||
ad_top_y_norm = 0.78 # 恢复默认的点击边界 (0.78),不再需要为了避开兔子而设为 0.90
|
||||
if ad_res:
|
||||
ad_type = ad_res.get("ad_type")
|
||||
if ad_type != "rabbit":
|
||||
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)
|
||||
@@ -179,11 +194,6 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
|
||||
# 重新截图
|
||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||
screenshot_path = take_screenshot(d, image_uuid, save_dir=TEMP_IMAGE_DIR)
|
||||
else:
|
||||
# 发现兔子广告,不再尝试关闭,直接计算它的顶边界 (归一化 0-1)
|
||||
# 我们取 0.90 作为安全阈值,低于此 Y 坐标的场站认为被遮挡
|
||||
ad_top_y_norm = 0.90
|
||||
logger.info(f">>> 发现兔子广告,设定安全边界为 Y_norm < {ad_top_y_norm}")
|
||||
|
||||
# 检查是否已经滚动到底部 (排除状态栏后,内容与上次一致)
|
||||
current_md5 = Kit.get_image_content_md5(
|
||||
@@ -270,7 +280,19 @@ async def get_station_list(d, service, uploader, max_scrolls=MAX_SCROLLS):
|
||||
if detail_ad_res:
|
||||
dad_type = detail_ad_res.get("ad_type")
|
||||
if dad_type == "rabbit":
|
||||
logger.info(">>> 详情页检测到 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})...")
|
||||
|
||||
@@ -756,12 +756,6 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
threshold_h = median_h * 0.70
|
||||
|
||||
for (y1, y2), card_h in zip(temp_valid_segments, heights):
|
||||
# 【优化】过滤顶部非场站区域 (例如会员图标、搜索栏等)
|
||||
# 场站列表通常在屏幕 35% 高度以后
|
||||
if y1 / h < 0.35:
|
||||
logger.info(f" Filtering out segment Y={y1}-{y2} because it's too high up (Top {y1/h:.2f} < 0.35).")
|
||||
continue
|
||||
|
||||
if card_h < threshold_h:
|
||||
logger.info(
|
||||
f" Filtering out segment Y={y1}-{y2} (H={card_h}) because it's too short (Threshold={threshold_h:.1f}).")
|
||||
|
||||
@@ -55,7 +55,18 @@ async def check_and_close_ad(d):
|
||||
logger.info(f"检测到广告关闭按钮: ({x}, {y}) [Type: {ad_type}]")
|
||||
|
||||
if ad_type == "rabbit":
|
||||
logger.info(">>> 检测到兔子广告。根据策略,我们不再尝试关闭它,直接继续。")
|
||||
logger.info(">>> 检测到兔子广告。尝试使用图片识别关闭...")
|
||||
try:
|
||||
# 使用用户验证有效的图片点击方法
|
||||
template_path = os.path.join(BASE_DIR, "Template", "X.jpg")
|
||||
if d.image.click(template_path, timeout=3.0):
|
||||
logger.info(">>> 成功通过图片识别关闭兔子广告。")
|
||||
await asyncio.sleep(1.5)
|
||||
else:
|
||||
logger.warning(">>> 图片识别未找到兔子广告关闭按钮,跳过。")
|
||||
except Exception as ex:
|
||||
logger.error(f">>> 图片识别关闭兔子广告异常: {ex}")
|
||||
|
||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||
return True
|
||||
else:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user