无法在python中使用beautiful soup获取图像源

2024-05-26 20:47:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从一篇文章中找到图片来源。你知道吗

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”中的那个


Tags: srccomfreehttpimgdatawwwmovies

热门问题