import requests
from bs4 import BeautifulSoup
class Weather:
URL = 'https://yandex.ru/pogoda/yaroslavl/month?via=cnav'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0', 'accept': '*/*'}
HOST = 'https://yandex.ru'
def get_html(url, params=None):
r = requests.get(url, headers=HEADERS, params=params)
return r
def get_content(html):
data = '25 июля'
soup = BeautifulSoup(html, 'html.parser')
items_day = soup.find_all('div', class_='climate-calendar-day')
days = []
for item in items_day:
if data == item.find('h6', class_='climate-calendar-day__detailed-day').get_text()[:-4]:
items_table = item.find_all('td', class_='climate-calendar-day__detailed-data-table-cell climate-calendar-day__detailed-data-table-cell_value_yes')
days.append({
'Погода днём': item.find('div', class_='temp climate-calendar-day__detailed-basic-temp-day').get_text(),
'Погода ночью': item.find('div', class_='temp climate-calendar-day__detailed-basic-temp-night').get_text(),
'Давление': item.find('td', class_='climate-calendar-day__detailed-data-table-cell climate-calendar-day__detailed-data-table-cell_value_yes').get_text(),
'Влажность': items_table[1].get_text(),
'Скорость ветра': item.find('div', class_='wind-speed').get_text() + ' м/с',
})
print(days)
return days
def parse():
html = get_html(URL)
if html.status_code == 200:
cars = get_content(html.text)
else:
print('Error')
parse()
Weather()
Нужно этот парсер потом к боту телеграмм прицепить, поэтому загнал в класс. Но в классе он выдает ошибку
Traceback (most recent call last):
File "WeatherYar.py", line 5, in
class Weather:
File "WeatherYar.py", line 43, in Weather
parse(URL)
File "WeatherYar.py", line 36, in parse
html = get_html(URL)
NameError: name 'get_html' is not defined
Подскажите, как лучше сделать, чтоб с ботом всё нормально работало