0

This is the code I obtain with BS4 and I succeed to write in a CSV

[<div class="clearfix hide-mobile" id="image-block"><span id="view_full_size"><span class="product_game-language"><svg class="svg-flag_en icon"><use xlink:href="#svg-flag_en"></use></svg></span><span class="ratio-container" style="max-width:372px"><img alt="Dominion - Plunder" height="372" id="bigpic" itemprop="image" loading="lazy" src="https://imageotoget.jpg" width="372"/></span></span></div>]

How can I get only the SRC attribute and not the entire tags text?

HedgeHog
  • 22,146
  • 4
  • 14
  • 36
  • 3
    Does this answer your question? [Extract the 'src' attribute from an 'img' tag using Beautiful Soup](https://stackoverflow.com/questions/43982002/extract-the-src-attribute-from-an-img-tag-using-beautiful-soup) – Ahmed Mohamedeen Jan 06 '23 at 21:23

1 Answers1

1
from bs4 import BeautifulSoup

html = '<div class="clearfix hide-mobile" id="image-block"><span id="view_full_size"><span class="product_game-language"><svg class="svg-flag_en icon"><use xlink:href="#svg-flag_en"></use></svg></span><span class="ratio-container" style="max-width:372px"><img alt="Dominion - Plunder" height="372" id="bigpic" itemprop="image" loading="lazy" src="https://imageotoget.jpg" width="372"/></span></span></div>'

soup = BeautifulSoup(html, 'html.parser')

element = soup.select_one('img')
src = element.attrs['src']
print(src)

or as @Ahmed Mohamedeen said

src = element['src']

result is the same

https://imageotoget.jpg
Ronin
  • 1,811
  • 1
  • 16
  • 17