'commit'
This commit is contained in:
@@ -199,24 +199,35 @@ class TeLaiDianCrawler(BaseCrawler):
|
|||||||
station_name = station_info.get("name")
|
station_name = station_info.get("name")
|
||||||
address = station_info.get("address")
|
address = station_info.get("address")
|
||||||
logger.info(f"[详情页] 进入 crawl_detail_logic,场站: {station_name} | 地址: {address}")
|
logger.info(f"[详情页] 进入 crawl_detail_logic,场站: {station_name} | 地址: {address}")
|
||||||
logger.info(f"[详情页] 已截取首屏截图,启动异步基础信息识别任务: {first_screen_path}")
|
logger.info(f"[详情页] 已截取首屏截图,准备识别基础信息: {first_screen_path}")
|
||||||
|
|
||||||
async def analyze_basic_info_background(image_path, fallback_name, fallback_address):
|
try:
|
||||||
try:
|
basic_info = await self.read_image_kit.analyze_detail_basic_info(first_screen_path)
|
||||||
basic_info = await self.read_image_kit.analyze_detail_basic_info(image_path)
|
if isinstance(basic_info, dict):
|
||||||
name2 = basic_info.get("name") or fallback_name
|
name2 = basic_info.get("name")
|
||||||
addr2 = basic_info.get("address") or fallback_address
|
addr2 = basic_info.get("address")
|
||||||
logger.info(f"[异步] 详情页基础信息识别完成: {name2} | {addr2}")
|
if name2:
|
||||||
except Exception as ex:
|
station_name = name2
|
||||||
logger.error(f"[异步] 分析详情页基础信息失败: {ex}")
|
if addr2:
|
||||||
finally:
|
address = addr2
|
||||||
if os.path.exists(image_path):
|
logger.info(f"[详情页] 同步基础信息识别结果用于写库: {station_name} | {address}")
|
||||||
try:
|
except Exception as ex:
|
||||||
os.remove(image_path)
|
logger.error(f"[详情页] 同步分析详情页基础信息失败: {ex}")
|
||||||
except:
|
finally:
|
||||||
pass
|
if os.path.exists(first_screen_path):
|
||||||
|
try:
|
||||||
|
os.remove(first_screen_path)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
asyncio.create_task(analyze_basic_info_background(first_screen_path, station_name, address))
|
template_xczs = os.path.join(os.path.dirname(__file__), "Template", "xczs.jpg")
|
||||||
|
try:
|
||||||
|
if os.path.exists(template_xczs):
|
||||||
|
if d.image.click(template_xczs, timeout=3.0):
|
||||||
|
logger.info("[详情页] 检测到温馨提示弹窗,已点击“下次再说”关闭。")
|
||||||
|
await asyncio.sleep(1.5)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[详情页] 通过模板点击关闭温馨提示弹窗失败: {e}")
|
||||||
|
|
||||||
w, h = d.window_size()
|
w, h = d.window_size()
|
||||||
logger.info("[详情页] 先执行一次较大的向上滑动,将详情内容上移一屏左右")
|
logger.info("[详情页] 先执行一次较大的向上滑动,将详情内容上移一屏左右")
|
||||||
@@ -427,7 +438,6 @@ class TeLaiDianCrawler(BaseCrawler):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 6. 保存数据
|
|
||||||
if all_prices:
|
if all_prices:
|
||||||
station_name_clean = clean_station_name(station_name)
|
station_name_clean = clean_station_name(station_name)
|
||||||
try:
|
try:
|
||||||
@@ -438,6 +448,13 @@ class TeLaiDianCrawler(BaseCrawler):
|
|||||||
await self.service.save_station_data(station_name_clean, address, all_prices)
|
await self.service.save_station_data(station_name_clean, address, all_prices)
|
||||||
else:
|
else:
|
||||||
logger.warning(f"❌ 未能提取到任何价格信息,请检查页面识别逻辑")
|
logger.warning(f"❌ 未能提取到任何价格信息,请检查页面识别逻辑")
|
||||||
|
if address:
|
||||||
|
station_name_clean = clean_station_name(station_name)
|
||||||
|
logger.info(f"[详情页] 虽未获取价格,但已获取地址,尝试仅保存基础信息: {station_name_clean} | {address}")
|
||||||
|
try:
|
||||||
|
await self.service.save_station_profile_only(station_name_clean, address)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[详情页] 仅保存基础信息失败: {e}")
|
||||||
if os.path.exists(price_screen_path):
|
if os.path.exists(price_screen_path):
|
||||||
os.remove(price_screen_path)
|
os.remove(price_screen_path)
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,29 @@ class TeLaiDianService:
|
|||||||
async def close_db(self):
|
async def close_db(self):
|
||||||
await self.db.close()
|
await self.db.close()
|
||||||
|
|
||||||
|
async def save_station_profile_only(self, station_name, address):
|
||||||
|
if not station_name or not address:
|
||||||
|
return False
|
||||||
|
|
||||||
|
station_hash = self.get_hash(station_name)
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
async with await self.db.get_session() as session:
|
||||||
|
profile_id = self.generate_id()
|
||||||
|
await self.station_profile_model.save(
|
||||||
|
session=session,
|
||||||
|
id=profile_id,
|
||||||
|
station_hash=station_hash,
|
||||||
|
operator=self.operator,
|
||||||
|
station_name=station_name,
|
||||||
|
address=address,
|
||||||
|
valid_start_time=now
|
||||||
|
)
|
||||||
|
await session.commit()
|
||||||
|
|
||||||
|
logger.info(f"仅保存场站基础信息: {station_name}")
|
||||||
|
return True
|
||||||
|
|
||||||
async def save_station_data(self, station_name, address, prices):
|
async def save_station_data(self, station_name, address, prices):
|
||||||
"""
|
"""
|
||||||
保存场站及其价格数据到数据库
|
保存场站及其价格数据到数据库
|
||||||
|
|||||||
BIN
Apps/TeLaiDian/Template/xczs.jpg
Normal file
BIN
Apps/TeLaiDian/Template/xczs.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.6 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user