Python lxml无法查看已解析标记的属性

Python lxml无法查看已解析标记的属性,python,lxml,Python,Lxml,我正在尝试解析一个图片链接,它位于'img'标记的'src'属性下 以下是来自浏览器的源html代码: <img class="athenaProductImageCarousel_image" data-hide="false" alt="ARKK Copenhagen Men's Asymtrix Mesh Trainers - Off White Ash" aria-role="presentation" aria-hidden="true" src="//s1.thcdn.com

我正在尝试解析一个图片链接,它位于'img'标记的'src'属性下

以下是来自浏览器的源html代码:

 <img class="athenaProductImageCarousel_image" data-hide="false" alt="ARKK Copenhagen Men's Asymtrix Mesh Trainers - Off White Ash" aria-role="presentation" aria-hidden="true" src="//s1.thcdn.com/productimg/1600/1600/12024279-9854653309695274.jpg" srcset="//s1.thcdn.com/productimg/20/20/12024279-9854653309695274.jpg 20w, 
//s1.thcdn.com/productimg/600/600/12024279-9854653309695274.jpg 600w, //s1.thcdn.com/productimg/270/270/12024279-9854653309695274.jpg 270w, //s1.thcdn.com/productimg/70/70/12024279-9854653309695274.jpg 70w, 
//s1.thcdn.com/productimg/300/300/12024279-9854653309695274.jpg 300w, //s1.thcdn.com/productimg/480/480/12024279-9854653309695274.jpg 480w, 
//s1.thcdn.com/productimg/50/50/12024279-9854653309695274.jpg 50w, //s1.thcdn.com/productimg/60/60/12024279-9854653309695274.jpg 60w, 
//s1.thcdn.com/productimg/180/180/12024279-9854653309695274.jpg 180w, //s1.thcdn.com/productimg/1600/1600/12024279-9854653309695274.jpg 1600w,
 //s1.thcdn.com/productimg/130/130/12024279-9854653309695274.jpg 130w, //s1.thcdn.com/productimg/960/960/12024279-9854653309695274.jpg 960w, //s1.thcdn.com/productimg/100/100/12024279-9854653309695274.jpg 100w, 
//s1.thcdn.com/productimg/200/200/12024279-9854653309695274.jpg 200w, 
//s1.thcdn.com/productimg/350/350/12024279-9854653309695274.jpg 350w">
    </div>

如果没有访问整个HTML的权限,就很难进行调试。 您确定页面上只有一个
athenaProductImageCarousel_图像吗

另外,您正在lxml中使用不同的类
athenaProductImageCarousel_imagePreview

element.xpath('//img[@class="athenaProductImageCarousel_imagePreview"]')[0]

这是故意的吗?

是否有其他img元素与同一类相关

看看element.xpath的返回中是否没有任何其他元素

另一种想法是,你似乎使用了错误的类

你想要什么:

element.xpath('//img[@class="athenaProductImageCarousel_image"]')[0]

你能再澄清一下你的问题吗?你的xpath不适合你的html。您无法获取它。如果页面使用JavaScript添加项目,则您可能无法获取项目,因为
lxml
无法运行JavaScriptp。@party ring添加了一些解释,但如果您需要更多,请询问meI,不要从服务器上的HTML中查看您的HTML,即使在浏览器中也是如此。可能他们为不同的设备/浏览器发送不同的内容,或者他们使用JavaScript添加这些项目。但它不会显示带有img url的“src”标记,因为任何classI都可以为您提供项目链接:我正在尝试解析图像url
element.xpath('//img[@class="athenaProductImageCarousel_imagePreview"]')[0]
element.xpath('//img[@class="athenaProductImageCarousel_image"]')[0]