'commit'
This commit is contained in:
@@ -120,6 +120,15 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
detail_check_path = take_screenshot(d, f"tld_detail_check_{int(time.time())}.jpg")
|
||||
logger.info(f"详情页快照已保存: {detail_check_path}")
|
||||
|
||||
# 简单验证:如果标题包含 "我的卡券"、"优惠券" 等,说明点错了
|
||||
is_wrong_page = await self.check_wrong_page(d, detail_check_path)
|
||||
if is_wrong_page:
|
||||
logger.warning(f"检测到进入了错误页面,尝试返回列表...")
|
||||
d.press("back")
|
||||
await asyncio.sleep(WAIT_BACK_TO_LIST)
|
||||
if os.path.exists(detail_check_path): os.remove(detail_check_path)
|
||||
continue
|
||||
|
||||
# 爬取详情
|
||||
await self.crawl_detail_logic(d, station)
|
||||
|
||||
@@ -136,6 +145,31 @@ class TeLaiDianCrawler(BaseCrawler):
|
||||
|
||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||
|
||||
async def check_wrong_page(self, d, image_path):
|
||||
"""
|
||||
检查是否误触进入了错误的页面(如:我的卡券、活动页等)
|
||||
"""
|
||||
prompt = """
|
||||
分析这张截图,判断这是否是一个“充电站详情页”。
|
||||
特征:详情页通常包含场站名称、电价列表、电桩状态等。
|
||||
如果页面显示的是“我的卡券”、“优惠券”、“个人中心”或“活动广告”,则不是详情页。
|
||||
|
||||
输出格式为 JSON:
|
||||
{
|
||||
"is_detail_page": true/false,
|
||||
"page_type": "detail" / "coupons" / "ad" / "other",
|
||||
"reason": "判断依据"
|
||||
}
|
||||
"""
|
||||
try:
|
||||
res_text = await self.read_image_kit.vlm.analyze_image(image_path, prompt)
|
||||
json_str = self.read_image_kit.vlm.extract_json(res_text)
|
||||
data = json.loads(json_str)
|
||||
return not data.get("is_detail_page", True)
|
||||
except Exception as e:
|
||||
logger.error(f"检查页面类型失败: {e}")
|
||||
return False
|
||||
|
||||
async def crawl_detail_logic(self, d, station_info):
|
||||
"""
|
||||
在详情页提取价格和状态信息
|
||||
|
||||
Reference in New Issue
Block a user