-1

need extract src in tag with beatifulsoup in python of tag 'div.participant-logo' .

import requests
import bs4

root_url = 'here url to parse'

response = requests.get(root_url)
soup = bs4.BeautifulSoup(response.text)

logo_cuadro1 = soup.select('div.participant-logo')

print (logo_cuadro1)

Code HTML

<td class="participant-logo"><a href="/futbol/espana/equipo-cordoba-cf-8004992.html"><img src="http://medias/logos/icons/teams-80/7869.png?v=2"></a></td>
Fabián
  • 39
  • 6

2 Answers2

0

To get the src:

soup = bs4.BeautifulSoup("""<td class="participant-logo"><a href="/futbol/espana/equipo-cordoba-cf-8004992.html"><img src="http://medias/logos/icons/teams-80/7869.png?v=2"></a></td>""")

logo_cuadro1 = soup.find("img")["src"]

print (logo_cuadro1)

http://medias/logos/icons/teams-80/7869.png?v=2

In your case:

sel  = soup.select('div.participant-logo')
link = sel[0].find("img")["src"]
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • Hi, this return error. logo_cuadro1 = soup.select('div.participant-logo').find("img")["src"] AttributeError: 'list' object has no attribute 'find' – Fabián Jan 16 '15 at 20:02
0

You can extend your CSS selection to the an image with src attribute:

for img in soup.select('div.participant-logo img[src]'):
    print img['src']
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343