Установи lxml, если не установлен:
pip install lxml
--------------------------------------
import requests
from bs4 import BeautifulSoup
spicok = []
r = requests.get('https://export.yandex.ru/bar/reginfo.xml?region=76')
soup = BeautifulSoup(r.text, 'lxml')
element = 'title'
find_element = soup.find(element)
# print(soup)
print(find_element.text)
Готовая реализация:
import requests
from bs4 import BeautifulSoup
def get_spicok(*args):
spicok = []
for element in args:
try:
find_element = soup.find(element)
spicok.append(find_element.text)
except AttributeError:
print(f'Тег <{element}> не найден!')
return spicok
r = requests.get('https://export.yandex.ru/bar/reginfo.xml?region=76')
soup = BeautifulSoup(r.text, 'lxml')
spicok = get_spicok('title', 'wind_speed', 'и тд')
print(spicok) # Вывод:
# Тег <и тд> не найден!
# ['Хабаровск', '2']