【发布时间】:2018-08-25 19:13:42
【问题描述】:
我一直在尝试使用 Scrapy(xpath) 从脚本标签中提取数据。我的主要问题是识别正确的 div 和 script 标签。我是使用 xpath 的新手,如果能提供任何帮助,我将不胜感激!
<script>
var COUNTRY_SHOP_STATUS = "buy";
var COUNTRY_SHOP_URL = "";
try {
digitalData.page.pathIndicator.depth_2 = "mobile";
digitalData.page.pathIndicator.depth_3 = "mobile";
digitalData.page.pathIndicator.depth_4 = "smartphones";
digitalData.page.pathIndicator.depth_5 = "galaxy-s8";
digitalData.product.pvi_type_name = "Mobile";
digitalData.product.pvi_subtype_name = "Smartphone";
digitalData.product.model_name = "SM-G950F";
digitalData.product.category = digitalData.page.pathIndicator.depth_3;
} catch(e) {}
</script>
我终于想用 model.name 和深度 3、4 和 5 的数据填充我的 csv 文件。我已经尝试了与此类似的问题中的其他解决方案,但它们似乎不起作用......
【问题讨论】:
-
您能否提供一个您尝试从中提取信息的数据样本?
-
“我已经尝试了其他解决方案...” 究竟是哪些解决方案?分享当前和期望的输出
-
@Ggg 谢谢你的回答!所以我试图访问的网址是这个:samsung.com/uk/smartphones/galaxy-s8。这仅适用于 Galaxy S8,但我也需要访问其他的。 Galaxy S9、Note 9 等。我想从该脚本标签中检索以下数据:我想从 digitalData.product.pvi_subtype_name = 等变量中获取以下值:“Smartphone”、“galaxy-s9”、“mobile” “手机”;或 digitalData.page.pathIndicator.depth_5 = "galaxy-s8";我想将这些值存储在 CSV 文件中。
-
@Andersson 也感谢您的回答!我查看了以下主题 stackoverflow.com/questions/47721021/… 和 stackoverflow.com/questions/43871064/…。我已经编辑了那里提供的解决方案,但它们对我不起作用。
标签: javascript python web-scraping scrapy