从div类XPath中提取图像url作为字符串



我在使用xpath从amazon提取一些图像URL时遇到了一些问题。

我试图提取url的页面是这个,作为一个例子

https://www.amazon.com/Touchscreen-Laptop-Tablet-Windows-Quad-Core/dp/B07FYX613Z/ref=sr_1_23/147-3050782-9544926?s=pc&ie=UTF8&qid=1542390985&sr=1-23&keywords=游戏+笔记本电脑&精制=p_36%3A-100000

我有这个:

<div id="ivLargeImage" style="height: 573px; display: block; opacity: 1; visibility: visible; cursor: zoom-in;"><img src="https://images-na.ssl-images-amazon.com/images/I/81zqMok22fL._SL1500_.jpg" class="fullscreen" style="margin-top: 10px; margin-left: 252px; height: 553px; width: 573px;"></div>
<img src="https://images-na.ssl-images-amazon.com/images/I/81zqMok22fL._SL1500_.jpg" class="fullscreen" style="margin-top: 10px; margin-left: 252px; height: 553px; width: 573px;">

我的目标是https://images-na.ssl-images-amazon.com/images/I/81zqMok22fL.SL1500.jpg

我目前正在使用xpath

//div[contains(@id, "ivLargeImage")]/img/@src

这实际上给了我https://images-na.ssl-images-amazon.com/images/I/81zqMok22fL.当我使用XPath Helper 进行检查时,SL1500.jpg

问题是,当我用提取信息时

item['img0Product']= response.xpath('//div[contains(@id, "ivLargeImage")]/img/@src').extract()

该变量中没有显示任何数据。

编辑:添加了亚马逊链接

我可以通过以下XPath:获得所需的图像

//div[@id="imgTagWrapperId"]/img/@data-old-hires

试着让我知道,以防它不能按预期工作

也许可以尝试extract_first()而不是extract()

extract()通常返回一个选择器列表,而不是单个值。

最新更新