При вводе команлы /weather бот выдаёт вместо информации о погоде ошибку: **<function get_weather.<locals>.parse at 0x000000000359B040>
import requests**
from bs4 import BeautifulSoup
from datetime import datetime, timedelta, time
import telebot
bot = telebot.TeleBot('TOKEN')
HMS = '%H:%M:%S'
timeNY = datetime.utcnow()+timedelta(hours=-5)
URL = 'https://yandex.ru/pogoda/odincovo'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 YaBrowser/20.12.2.108 Yowser/2.5 Safari/537.36', 'accept': '*/*'}
@bot.message_handler(commands=['weather'])
def get_weather(message):
def get_html(url, params=None):
r = requests.get(url, headers=HEADERS, params=params)
return r
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('div', class_='forecast-briefly__day swiper-slide')
weather = []
for item in items:
weather.append ({
'title': item.find('div', class_='forecast-briefly__name').get_text(strip=True),
'day': item.find('div', class_='temp forecast-briefly__temp forecast-briefly__temp_day').get_text(strip=True),
'night': item.find('div', class_='temp forecast-briefly__temp forecast-briefly__temp_night').get_text(strip=True),
'conditions': item.find('div', class_='forecast-briefly__condition').get_text(strip=True)
})
return weather
def parse():
html = get_html(URL)
if html.status_code == 200:
weather = get_content(html.text)
print (weather)
parse()
bot.send_message(message.from_user.id, parse)