有没有什么方法可以通过 BeautifulSoup 获取有关想象大小的信息?

我正在尝试使用 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 高度和宽度。有任何想法吗?谢谢


喵喔喔
浏览 108回答 1
1回答

千万里不及你

尝试类似的东西:for link in soup.findAll("a",href=str(match)):&nbsp; &nbsp; target = link.select_one('img')&nbsp; &nbsp; print("Height: ",target.attrs['height'])&nbsp; &nbsp; print("Width: ",target.attrs['width'])输出:Height:&nbsp; 263Width:&nbsp; 500
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python