Aug-18-2022, 04:56 PM
I'm trying to web scrape the attribute "alt" from a "img" tag of this website: https://www.meteo.it/meteo/roma-oggi-58091. As you may understand, even if the website is in Italian, it's a weather forecast website. The image I'm trying to scrape the "alt" attribute from is the first image: the one that shows the weather at current time (next to the writing "ore" + the hour). I need to webscrape the "alt" attribute because it contains the written infos about the current weather. How should I do that? I'm using Beautiful Soup.
This is the code I've written, but it seems to find no "alt" attribute. In fact, the output is just "[ ]". If I print the variable "img_weather", on the other hand, it prints various "img" tags which do have the attribute I'm looking for.
This is the code I've written, but it seems to find no "alt" attribute. In fact, the output is just "[ ]". If I print the variable "img_weather", on the other hand, it prints various "img" tags which do have the attribute I'm looking for.
from cmath import inf import bs4, requests, webbrowser LINK = "https://www.meteo.it/meteo/roma-oggi-58091" response = requests.get(LINK) response.raise_for_status() soup = bs4.BeautifulSoup(response.text, 'html.parser') img_weather = soup.findAll('img') alt_weather = [] for img in img_weather: alt = str(img.find('img')) if alt != 'None': alt_weather.append(alt) print(alt_weather)Thanks in advance.