CodeRic
CodeRic

Reputation: 21

How can I get the url of "src=..."?

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

Answers (1)

Feodoran
Feodoran

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

Related Questions