'commit'
This commit is contained in:
@@ -21,9 +21,8 @@ from Apps.AiTeJiYiChong.Service import AiTeJiYiChongService
|
||||
from Config.Config import TEMP_IMAGE_DIR
|
||||
from Apps.AiTeJiYiChong.Config.Setting import (
|
||||
SCROLL_DISTANCE_RATIO,
|
||||
MAX_SCROLLS, REDIS_STATION_EXPIRE,
|
||||
MAX_STATIONS_COUNT, REDIS_STATION_EXPIRE,
|
||||
WAIT_AFTER_SCROLL,
|
||||
MAX_CRAWL_DISTANCE,
|
||||
SAFE_EXCLUDE_RATIO,
|
||||
BOTTOM_SAFE_EXCLUDE_RATIO
|
||||
)
|
||||
@@ -43,7 +42,7 @@ async def is_already_crawled(redis_kit, station_name):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def get_station_list(d, service, max_scrolls=MAX_SCROLLS):
|
||||
async def get_station_list(d, service, max_stations_count=MAX_STATIONS_COUNT):
|
||||
"""
|
||||
获取场站列表并处理翻页
|
||||
"""
|
||||
@@ -55,15 +54,18 @@ async def get_station_list(d, service, max_scrolls=MAX_SCROLLS):
|
||||
device_info['width'] = w
|
||||
device_info['height'] = h
|
||||
|
||||
logger.info(f"开始爬取列表,设备: {device_info.get('productName')} | 分辨率: {w}x{h}")
|
||||
logger.info(f"开始爬取列表,设备: {device_info.get('productName')} | 分辨率: {w}x{h} | 目标数量: {max_stations_count}")
|
||||
|
||||
# 用于追踪后台分析任务
|
||||
background_tasks = []
|
||||
last_list_md5 = None
|
||||
no_new_data_count = 0
|
||||
total_processed_count = 0
|
||||
scroll_count = 0
|
||||
|
||||
for i in range(max_scrolls + 1):
|
||||
logger.info(f"正在处理第 {i + 1} 页...")
|
||||
while total_processed_count < max_stations_count:
|
||||
scroll_count += 1
|
||||
logger.info(f"正在处理第 {scroll_count} 次滚动 (已采集: {total_processed_count}/{max_stations_count})...")
|
||||
|
||||
# 1. 拍摄截图
|
||||
image_uuid = str(uuid.uuid4())
|
||||
@@ -127,8 +129,9 @@ async def get_station_list(d, service, max_scrolls=MAX_SCROLLS):
|
||||
|
||||
# 正常处理新场站
|
||||
click_x, click_y = card["click_point"]
|
||||
logger.info(f"准备处理第 {card_idx + 1} 个场站: {station_name}, 点击坐标: ({click_x}, {click_y})")
|
||||
logger.info(f">>> 发现新场站 '{station_name}',开始处理... ({total_processed_count + 1}/{max_stations_count})")
|
||||
new_stations_processed += 1
|
||||
total_processed_count += 1
|
||||
d.click(click_x, click_y)
|
||||
|
||||
# 等待二级页面加载
|
||||
@@ -230,6 +233,13 @@ async def get_station_list(d, service, max_scrolls=MAX_SCROLLS):
|
||||
full_name_key = f"crawled:aite:{Kit.clean_station_name(station_name)}"
|
||||
await redis_kit.set_data(full_name_key, "1", expire=REDIS_STATION_EXPIRE)
|
||||
|
||||
# 检查是否已达到最大采集数量
|
||||
if total_processed_count >= max_stations_count:
|
||||
logger.info(f"已达到目标采集数量 {max_stations_count},准备结束采集。")
|
||||
break
|
||||
if total_processed_count >= max_stations_count:
|
||||
break
|
||||
|
||||
# 在每一页结束时,清理已完成的任务
|
||||
done_tasks = [t for t in background_tasks if t.done()]
|
||||
for t in done_tasks:
|
||||
@@ -258,7 +268,7 @@ async def get_station_list(d, service, max_scrolls=MAX_SCROLLS):
|
||||
logger.info(f"正在等待剩余 {len(background_tasks)} 个后台分析任务完成...")
|
||||
await asyncio.gather(*background_tasks, return_exceptions=True)
|
||||
|
||||
logger.info("达到最大翻页次数,爬取结束。")
|
||||
logger.info(f"采集任务完成,共采集 {total_processed_count} 个场站。")
|
||||
return True
|
||||
|
||||
async def analyze_prices_background(service, station_name, image_paths):
|
||||
|
||||
Reference in New Issue
Block a user