I'm trying to download the 7 days forecast from https://www.yandex.com/weather/moscow The problem is all the days except today have the same class. How do I get the forecast for 7 days (or at least for 9)?
I'm trying the BeautifulSoap library. I've got today weather, but all the other days are a problem.
Here is the code I have:
import urllib.request
from bs4 import BeautifulSoup
def get_html(url):
response = urllib.request.urlopen(url)
return response.read()
def parse_today(html):
soup = BeautifulSoup(html, "html.parser")
temp = soup.find('div', class_='temp fact__temp fact__temp_size_s').get_text().encode('utf-8').decode('utf-8', 'ignore')
return temp
def parse_next_day(day_num, html):
# ?????
pass
def main():
temp = parse_today(get_html('https://yandex.ru/weather/moscow'))
print("Now the temperature is: ", temp)
for i in range(1,6):
next_temp = parse_next_day(i+1, get_html('https://yandex.ru/weather/moscow'))
print("The day", i+1, "temperature is : ", next_temp)
if __name__ == '__main__':
main()