I am given a HTML code, a part which particularly interests me looks like this:
<a href="/go/wydarzenia/rozrywka/35826-majowka-w-twierdzy-klodzko?
termin=265036" class="link with-img"> <img
src="/go/resources/main/img//download/img-
14ab4e372df7bd0826c90f429f0e5933/twierdza-przewodnik-jpg.jpg" alt="Majówka w
Twierdzy Kłodzko" class=""/>
I know that it looks a bit messy but I have to deal with it anyhow.
My job is to extract the text after alt.
So in the code above the output should look like this
>> Majówka w Twierdzy Kłodzko
I read here a lot of useful information about extracting data by searching CSS classes or HTML tags. However I didn't find anything anout alt. I would appreciate any help.
Here's my code after some changes
import requests
from bs4 import BeautifulSoup
url = 'https://www.wroclaw.pl/go/wydarzenia/rozrywka/eventy'
soup = BeautifulSoup(requests.get(url).content, "html.parser")
print(soup.a.img.attrs["alt"])
And the output says that:
AttributeError: 'NoneType' object has no attribute 'attrs'
What am I doing wrong?