This commit is contained in:
HuangHai
2026-01-16 21:29:49 +08:00
parent 3f3eb5ee05
commit aea318ce80
9 changed files with 23 additions and 35 deletions

View File

@@ -1,7 +1,7 @@
# 采集配置
SCROLL_DISTANCE_RATIO = 0.5
MAX_STATIONS_COUNT = 30
MAX_STATIONS_COUNT = 1
FIRST_RUN_ONLY_ONE_STATION = False
REDIS_STATION_EXPIRE = 120
DATA_RETENTION_DAYS = 365

View File

@@ -316,43 +316,23 @@ async def get_station_list(d, service, uploader, max_stations_count=MAX_STATIONS
if before_click_md5 != after_click_md5:
entered_price_page = True
price_screenshots = []
w, h = d.window_size()
scroll_x = int(w * 0.5)
scroll_top_y = int(h * 0.6)
scroll_bottom_y = int(h * 0.85)
# 1. 向下滚动到底 (根据用户反馈只有不断向下滚动才能看到00点的)
logger.info("正在向下滚动价格列表到底部 (快速多次滚动以尽快看到 00:00)...")
max_scroll_down = 10
for i in range(max_scroll_down):
before_scroll_path = take_screenshot(d, f"scroll_dn_{i}", save_dir=TEMP_IMAGE_DIR)
before_scroll_md5 = Kit.get_image_content_md5(before_scroll_path)
d.swipe_ext("up", scale=0.8)
await asyncio.sleep(0.3)
after_scroll_path = take_screenshot(d, f"scroll_dn_after_{i}", save_dir=TEMP_IMAGE_DIR)
after_scroll_md5 = Kit.get_image_content_md5(after_scroll_path)
# 清理临时截图
if os.path.exists(before_scroll_path): os.remove(before_scroll_path)
if os.path.exists(after_scroll_path): os.remove(after_scroll_path)
if before_scroll_md5 == after_scroll_md5:
logger.info(f"价格列表已到达底部 (滚动次数: {i})")
break
# 2. 向上滚动并逐页截图 (从底向上抓取)
logger.info("正在向上滚动价格列表并逐页截图...")
logger.info("从当前时段开始向下浏览价格列表并逐页截图...")
max_scroll_up = 10
for p_idx in range(1, max_scroll_up + 1):
# 截图当前页
p_uuid = f"{hashlib.md5(station_name.encode('utf-8')).hexdigest()}_p_{p_idx}"
p_path = take_screenshot(d, p_uuid, save_dir=TEMP_IMAGE_DIR)
price_screenshots.append(p_path)
# 检查是否还能向上滚动
before_up_md5 = Kit.get_image_content_md5(p_path)
d.swipe_ext("down", scale=0.85)
d.swipe(scroll_x, scroll_bottom_y, scroll_x, scroll_top_y, 0.2)
await asyncio.sleep(0.3)
# 检查是否还有新内容
check_up_path = take_screenshot(d, f"check_up_{p_idx}", save_dir=TEMP_IMAGE_DIR)
after_up_md5 = Kit.get_image_content_md5(check_up_path)
if os.path.exists(check_up_path): os.remove(check_up_path)

View File

@@ -57,13 +57,21 @@ async def check_and_close_ad(d):
if ad_type == "rabbit":
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)
template_path_1 = os.path.join(BASE_DIR, "Template", "X1.jpg")
template_path_2 = os.path.join(BASE_DIR, "Template", "X2.jpg")
clicked = False
if d.image.click(template_path_1, timeout=3.0):
logger.info(">>> 成功通过图片识别关闭兔子广告 (X1 模板)。")
clicked = True
else:
logger.warning(">>> 图片识别未找到兔子广告关闭按钮,跳过")
logger.warning(">>> X1 模板未找到兔子广告关闭按钮,尝试 X2 模板")
if d.image.click(template_path_2, timeout=3.0):
logger.info(">>> 成功通过图片识别关闭兔子广告 (X2 模板)。")
clicked = True
else:
logger.warning(">>> X2 模板也未找到兔子广告关闭按钮。")
if clicked:
await asyncio.sleep(1.5)
except Exception as ex:
logger.error(f">>> 图片识别关闭兔子广告异常: {ex}")

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 897 B