这里提取src属性是我的代码:Beautifulsoup不能从IMG标记
html = '''<img onload='javascript:if(this.width>950) this.width=950'
src="http://ww4.sinaimg.cn/mw600/c3107d40jw1e3rt4509j.jpg">'''
soup = BeautifulSoup(html)
imgs = soup.findAll('img')
print imgs[0].attrs
它将打印[(u'onload', u'javascript:if(this.width>950) this.width=950')]
那么,是src
属性?
如果我取代HTML通过类似html = '''<img src="/image/fluffybunny.jpg" title="Harvey the bunny" alt="a cute little fluffy bunny" />'''
我得到正确的结果为[(u'src', u'/image/fluffybunny.jpg'), (u'title', u'Harvey the bunny'), (u'alt', u'a cute little fluffy bunny')]
我很新的HTML和beautifulsoup。我错过了一些知识吗?感谢您的任何想法。
感谢精湛的答案,所有的细节。我没有配置SO自动发送回复我的电子邮件,所以我读了这么晚。我安装了bs4,它工作正常! – foresightyj
@foresightyj哈哈没问题:) – TerryA