来自这样的 html/rss 片段
[...]<div class="..." style="..."></div><p><a href="..."
<img alt="" heightt="" src="http://link.to/image"
width="" /></a><span style="">[...]
我想获取图片源链接“http://link.to/image.jpg”。我怎么能在 python 中做到这一点?谢谢。
最佳答案
lxml
是完成工作的工具。
要从网页中抓取所有图片就这么简单:
import lxml.html
tree = lxml.html.parse("http://example.com")
images = tree.xpath("//img/@src")
print images
给予:
['/_img/iana-logo-pageheader.png', '/_img/icann-logo-micro.png']
如果它是一个 RSS 提要,您需要使用 lxml.etree
来解析它。
关于python:从html获取图像链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5927031/