网站的html如下:
<div class="breed-image">
<img src = "link to image">
</div>
当我这样做时:
soup = BeautifulSoup(response.text, 'lxml')
for link in soup.find_all(class_='breed-image'):
print(link)
所有这一切都打印出来:
<div class="breed-image">
</div>
我也尝试过print(link.text)
所有这一切都打印出来:
None
感谢任何形式的帮助,谢谢!
答案 0 :(得分:0)
几个选项:
>>> soup.img['src']
'link to image'
>>> for link in soup.find_all('img'):
... print(link['src'])
...
link to image
答案 1 :(得分:0)
看起来您可能最好点击此页面调用的API来获取其图像:
In [13]: r = requests.get('https://dog.ceo/api/breeds/image/random')
In [14]: r.json()
Out[14]:
{'message': 'https://dog.ceo/api/img/terrier-dandie/n02096437_1790.jpg',
'status': 'success'}