无法使用python中的美丽汤来获取图像源

时间:2018-04-09 09:24:20

标签: python beautifulsoup

我正在尝试从文章中获取图像源。

import requests
from bs4 import BeautifulSoup

url = "http://www.thehindu.com/entertainment/movies/why-does-kollywood-lack-financial-transparency/article23432094.ece"
res = requests.get(url)
soup = BeautifulSoup(res.content, 'html.parser')
body = soup.find("body")
imageparentobject = body.find("div", class_="lead-img-cont")
image = imageparentobject.find("img", "lead-img")
print image['src']

这是上述代码的输出:

http://www.thehindu.com/static/img/1x1_spacer.gif

这是图像元素。

<img src="http://www.thehindu.com/entertainment/movies/article23432092.ece/
alternates/FREE_660/04mp-trade2jpg" data-variant="FREE" data-device-variant="FREE~
FREE~FREE" data-src-template="http://www.thehindu.com/entertainment/movies/article
23432092.ece/BINARY/thumbnail/04mp-trade2jpg" data-proxy-image="http://www.thehind
u.com/entertainment/movies/article23432092.ece/ALTERNATES/FREE_215/04mp-trade2jpg"
data-proxy-width="" style="width:100%;" alt="Why does Kollywood lack financial tra
nsparency?" title="Why does Kollywood lack financial transparency?" class="media-o
bject adaptive placeholder lead-img">

这是我需要的来源:

http://www.thehindu.com/entertainment/movies/article23432092.ece/alternates/FREE_660/04mp-trade2jpg

而不是'data-src-template'

中的那个

0 个答案:

没有答案