kan3k1k3n
@kan3k1k3n

Как исправить ошибку list index out of range?

у меня есть телеграм-бот, который выдает погоду в определенных городах. раньше все работало:

64070c03c8970114894379.png

а теперь при запуске парсера выдает ошибку list index out of range, хотя в яндексе не менялись названия для тегов span и т.д.
вот код парсера:
import requests
from bs4 import BeautifulSoup

url1 = 'https://yandex.ru/pogoda/?lat=55.685603&lon=37.746871'
url2 = 'https://yandex.ru/pogoda/?lat=59.93909836&lon=30.31587601'
url3 = 'https://yandex.ru/pogoda/?lat=55.03020096&lon=82.92043304'
url4 = 'https://yandex.ru/pogoda/?lat=56.8380127&lon=60.59747314'
url5 = 'https://yandex.ru/pogoda/?lat=55.79612732&lon=49.10641479'
url6 = 'https://yandex.ru/pogoda/?lat=56.32679749&lon=44.00651932'
url7 = 'https://yandex.ru/pogoda/?lat=55.15990067&lon=61.40255737'
resp1 = requests.get(url1)
resp2 = requests.get(url2)
resp3 = requests.get(url3)
resp4 = requests.get(url4)
resp5 = requests.get(url5)
resp6 = requests.get(url6)
resp7 = requests.get(url7)
bs1 = BeautifulSoup(resp1.text, 'lxml')
bs2 = BeautifulSoup(resp2.text, 'lxml')
bs3 = BeautifulSoup(resp3.text, 'lxml')
bs4 = BeautifulSoup(resp4.text, 'lxml')
bs5 = BeautifulSoup(resp5.text, 'lxml')
bs6 = BeautifulSoup(resp6.text, 'lxml')
bs7 = BeautifulSoup(resp7.text, 'lxml')
temperatura1 = bs1.find_all('span', class_="temp__value temp__value_with-unit") [1]
temperatura2 = bs2.find_all('span', class_="temp__value temp__value_with-unit") [1]
temperatura3 = bs3.find_all('span', class_="temp__value temp__value_with-unit") [1]
temperatura4 = bs4.find_all('span', class_="temp__value temp__value_with-unit") [1]
temperatura5 = bs5.find_all('span', class_="temp__value temp__value_with-unit") [1]
temperatura6 = bs6.find_all('span', class_="temp__value temp__value_with-unit") [1]
temperatura7 = bs7.find_all('span', class_="temp__value temp__value_with-unit") [1]
text1 = f'температура в Москве на сегодня: {temperatura1.text}°'
text2 = f'температура в Санкт-Петербурге на сегодня: {temperatura2.text}°'
text3 = f'температура в Новосибирске на сегодня: {temperatura3.text}°'
text4 = f'температура в Екатеринбурге на сегодня: {temperatura4.text}°'
text5 = f'температура в Казани на сегодня: {temperatura5.text}°'
text6 = f'температура в Нижнем Новгороде на сегодня: {temperatura6.text}°'
text7 = f'температура в Челябинске на сегодня: {temperatura7.text}°'

как исправить парсер, чтобы выдавало значение погоды?
  • Вопрос задан
  • 91 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы