Reputation: 21
I am trying to loop through all the img classes here but I am not sure how I can get the src= link
import requests
from bs4 import BeautifulSoup
url = 'https://giphy.com/search/anxiety'
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
gifs = soup.findAll("img", attrs={"class": "giphy-gif-img"})
for gif in gifs:
print(gif.get('image-src'))
Upvotes: 2
Views: 67
Reputation: 1822
In your last line, you can use gif.get('src')
.
However, gifs
is empty since there are no images with class=giphy-gif-img
on the page.
Upvotes: 1