gpt4 book ai didi

python - 如何在python中使用lxml获取img的src?

转载 作者:太空狗 更新时间:2023-10-30 01:51:51 29 4
gpt4 key购买 nike

我尝试使用 lxml 从 python 中的图像标记解析 src,但是当我尝试输出 imageurl 时,我得到以下信息:

[<Element img at 0x921f68c>]

这是我的代码:

xhtml = lxml.html.document_fromstring(html)
imageUrl = xhtml.xpath('//img[@alt="something"]')

最佳答案

只需将 /@src 附加到您的 xpath 表达式:

imageUrl = xhtml.xpath('//img[@alt="something"]/@src')

关于python - 如何在python中使用lxml获取img的src?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343169/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com