I am trying to get the image source from an article.
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']
This is the output for the above code:
http://www.thehindu.com/static/img/1x1_spacer.gif
This is the image element.
<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">
This is the source I need:
http://www.thehindu.com/entertainment/movies/article23432092.ece/alternates/FREE_660/04mp-trade2jpg
and not the one in 'data-src-template'