I am using Beautiful Soup to extract specific data out of a webpage.
I tried to get an attribute of a specific tag, but I failed.
I have to extract the attribute 'title' from the tag.
Here is the specific html tag I tried to get the attribute from:
<span id="currwx_icon" style="display: block;" class="weather_icon1 wxico_l_23a" title="Cloudy"></span>
Here are the codes I ran:
import requests
from bs4 import BeautifulSoup
data = requests.get('https://worldweather.wmo.int/en/city.html?cityId=206')
data = BeautifulSoup(data.text, 'html.parser')
today_weather = data.select('#currwx_icon')
for info in today_weather:
print(info['title'])
In this case, I get an error
KeyError: 'title'
import requests
from bs4 import BeautifulSoup
data = requests.get('https://worldweather.wmo.int/en/city.html?cityId=206')
data = BeautifulSoup(data.text, 'html.parser')
today_weather = data.select('#currwx_icon')
for info in today_weather:
print(info.attrs)
In this case, it does return a list of attributes but the attribute title is omitted
{'id': 'currwx_icon', 'class': ['weather_icon1'], 'style': 'display: block;'}
This is the webpage I am trying to extract data from: https://worldweather.wmo.int/en/city.html?cityId=206
What am I missing here??? And thank you in advance!