我正在尝试使用BeautifulSoup获得与某个链接相关的图像大小。 使用:
match="http://www.something.com"
link in soup.findAll("a",href=str(match))
我得到了
<a href="http://www.something.com"><img alt="Immagine" class="aligncenter size-large wp-image-4405" height="263" src="http://www.infographiclov.com/Immagine-500x263.jpg" width="500"/></a>
我能够得到href,但我想得到img alt高度和宽度。 有什么想法吗? 谢谢
请尝试如下操作:
for link in soup.findAll("a",href=str(match)):
target = link.select_one('img')
print("Height: ",target.attrs['height'])
print("Width: ",target.attrs['width'])
输出:
Height: 263
Width: 500