import lxml.html
import requests
html = requests.get('http://www.google.com/').text
doc = lxml.html.document_fromstring(html)
images = doc.xpath('//img') # here you can find the element in your case the image
if images:
print images[0].get('src') # here I get the src from the first img
else:
print "Images not found"
您可以尝试使用lxml(http://lxml.de/)和xpath(http://en.wikipedia.org/wiki/XPath)
例如,要在html中查找图像,可以
我希望这能对你有所帮助。你知道吗
更新:我修复了之前没有的else“:”
漂亮的汤文档有很好的“快速入门”部分:http://www.crummy.com/software/BeautifulSoup/bs4/doc/#quick-start
相关问题 更多 >
编程相关推荐