我正在尝试解析图片链接,该链接位于“img”标签中的“src”属性下 here
这是来自浏览器的源 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>
这是我使用 lxml 得到的结果:
<img class="athenaProductImageCarousel_image" data-hide="true" alt="ARKK Copenhagen Men's Asymtrix Mesh Trainers - Off White Ash" aria-role="presentation" aria-hidden="true"/>
</div>
我不知道为什么,我只是使用这段代码:
该元素是用lxml解析的lxml标签对象
element.xpath('//img[@class="athenaProductImageCarousel_imagePreview"]')[0]
最佳答案
如果无法访问整个 HTML,调试将会很困难。
您确定页面上只有一个 athenaProductImageCarousel_image
吗?
此外,您在 lxml 中使用不同的类 athenaProductImageCarousel_imagePreview
element.xpath('//img[@class="athenaProductImageCarousel_imagePreview"]')[0]
这是故意的吗?
关于python - lxml看不到解析标签的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57042966/