提问者:小点点

有没有什么modo来获取有关美人汤的imagine size的信息?


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


共1个答案

匿名用户

请尝试如下操作:

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