fix(爬虫): 更新上证所数据抓取的XPath并添加备用路径

原XPath无法定位元素,更新为更精确的路径并添加多个备用XPath
This commit is contained in:
2026-01-12 10:39:46 +08:00
parent 79e4ef3de5
commit 33c2af5348

View File

@@ -185,7 +185,7 @@ class SpiderManager:
return {}
sse_url = "https://www.sse.com.cn/"
xpath = "//*[@id=\"hq_area\"]"
xpath = "//*[@id=\"hq_controller\"]/table/tbody/tr/td[1]/rowspan[2]/i[1]"
logger.info(f"开始爬取上海证券交易所数据: {sse_url}")
@@ -204,6 +204,7 @@ class SpiderManager:
logger.warning("未找到股票数据元素尝试备用XPath")
# 尝试备用XPath
backup_xpaths = [
"//*[@id='hq_area']",
"//*[@id='hq_controller']//td[contains(@class, 'price')]//text()",
"//*[contains(@class, 'stock-price')]//text()",
"//*[contains(@class, 'price')]//text()"