'commit'
This commit is contained in:
Binary file not shown.
@@ -71,6 +71,7 @@ class YiLaiTeCrawler(BaseCrawler):
|
||||
await self.redis_kit.delete(*keys)
|
||||
|
||||
async def crawl_list_logic(self, d):
|
||||
w, h = d.window_size()
|
||||
max_to_crawl = 1 if FIRST_RUN_ONLY_ONE_STATION else MAX_STATIONS_COUNT
|
||||
processed_count = 0
|
||||
no_new_data_count = 0
|
||||
@@ -163,35 +164,62 @@ class YiLaiTeCrawler(BaseCrawler):
|
||||
detail_shots = []
|
||||
|
||||
if dqdf_pos:
|
||||
logger.info(f"发现‘阶段性电价’按钮 {dqdf_pos},点击进入...")
|
||||
logger.info(f"发现价格入口按钮 (阶段性电价/当前电费) {dqdf_pos},点击进入...")
|
||||
d.click(dqdf_pos[0], dqdf_pos[1])
|
||||
await asyncio.sleep(2) # 等待列表加载
|
||||
# 删除旧的详情页截图
|
||||
if os.path.exists(detail_shot): os.remove(detail_shot)
|
||||
|
||||
# 截图1 (顶部)
|
||||
shot1 = take_screenshot(d, f"detail_price_{clean_station_name(name)}_{int(time.time())}_1")
|
||||
detail_shots.append(shot1)
|
||||
# 1. 向下滚动到底 (根据用户反馈:只有不断向下滚动,才能看到00点的)
|
||||
logger.info("正在向下滚动价格列表到底部...")
|
||||
max_scroll_down = 6
|
||||
for i in range(max_scroll_down):
|
||||
before_scroll_path = take_screenshot(d, f"scroll_dn_{i}")
|
||||
before_scroll_md5 = get_image_content_md5(before_scroll_path)
|
||||
|
||||
d.swipe_ext("up", scale=0.8) # 向下滚动 = 手势向上
|
||||
await asyncio.sleep(1.2)
|
||||
|
||||
after_scroll_path = take_screenshot(d, f"scroll_dn_after_{i}")
|
||||
after_scroll_md5 = 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
|
||||
|
||||
# 向下滚动以获取完整价格表
|
||||
logger.info("向下滚动以获取更多电价信息(从底部向上滑)...")
|
||||
# User feedback: 必须放在下方,向上滚动
|
||||
w, h = d.window_size()
|
||||
# 调整滑动参数:避开底部导航栏,增加滑动距离,放慢速度
|
||||
# start_y=0.75, end_y=0.25
|
||||
d.swipe(w * 0.5, h * 0.75, w * 0.5, h * 0.25, 0.8)
|
||||
await asyncio.sleep(2.0) # 增加等待时间,确保滚动停止
|
||||
|
||||
# 截图2 (底部)
|
||||
shot2 = take_screenshot(d, f"detail_price_{clean_station_name(name)}_{int(time.time())}_2")
|
||||
detail_shots.append(shot2)
|
||||
# 2. 向上滚动并逐页截图 (从底向上抓取)
|
||||
logger.info("正在向上滚动价格列表并逐页截图...")
|
||||
max_scroll_up = 8
|
||||
for p_idx in range(1, max_scroll_up + 1):
|
||||
# 截图当前页
|
||||
p_shot = take_screenshot(d, f"detail_price_{clean_station_name(name)}_{int(time.time())}_{p_idx}")
|
||||
|
||||
# 检查是否还能向上滚动
|
||||
before_up_md5 = get_image_content_md5(p_shot)
|
||||
d.swipe_ext("down", scale=0.85) # 向上滚动 = 手势向下
|
||||
await asyncio.sleep(1.5)
|
||||
|
||||
# 检查是否还有新内容
|
||||
check_up_shot = take_screenshot(d, f"check_up_{p_idx}")
|
||||
after_up_md5 = get_image_content_md5(check_up_shot)
|
||||
if os.path.exists(check_up_shot): os.remove(check_up_shot)
|
||||
|
||||
detail_shots.append(p_shot)
|
||||
|
||||
if before_up_md5 == after_up_md5:
|
||||
logger.info(f"价格列表已到达顶部 (共抓取页数: {p_idx})")
|
||||
break
|
||||
|
||||
# 关闭分时段定价列表 (点击屏幕最顶部空白处)
|
||||
logger.info("点击屏幕上部空白处以关闭定价列表...")
|
||||
d.click(w * 0.5, h * 0.1)
|
||||
await asyncio.sleep(1.0)
|
||||
else:
|
||||
logger.info("未发现‘阶段性电价’按钮,直接分析当前页")
|
||||
logger.info("未发现价格入口按钮 (阶段性电价/当前电费),直接分析当前页")
|
||||
detail_shots.append(detail_shot)
|
||||
# --------------------------------------------------
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ def detect_price_info_container_cv(image_path):
|
||||
return None
|
||||
h, w = img.shape[:2]
|
||||
|
||||
keywords = ['阶段性电价']
|
||||
keywords = ['阶段性电价', '当前电费']
|
||||
|
||||
try:
|
||||
reader = get_ocr_reader()
|
||||
@@ -300,8 +300,8 @@ def detect_price_info_container_cv(image_path):
|
||||
x_max = np.max(pts[:, 0])
|
||||
y_max = np.max(pts[:, 1])
|
||||
|
||||
center_x = (x_min + x_max) // 2
|
||||
center_y = (y_min + y_max) // 2
|
||||
center_x = int((x_min + x_max) // 2)
|
||||
center_y = int((y_min + y_max) // 2)
|
||||
logger.info(f"[OCR识别] 找到文本: '{text}', 置信度: {prob:.4f}, 中心坐标: ({center_x}, {center_y})")
|
||||
return (center_x, center_y)
|
||||
except Exception as e:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user