Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup as BS
- def get_weather(city):
- r = requests.get('https://sinoptik.ua/погода-%s' % city.lower())
- #r = requests.get('https://sinoptik.com.by/погода-%s' % city.lower())
- html = BS(r.content, 'html.parser')
- res_ua = ''
- try:
- t_min = html.select('.temperature .min')[0].text
- t_max = html.select('.temperature .max')[0].text
- descr = html.select('.wDescription .description')[0].text
- res_ua = '%s %s %s' % (t_min, t_max, descr.strip())
- except Exception as err:
- print('error get weather from .ua site')
- pass
- res_by = ''
- try:
- temp = ' '.join(html.find('div', class_ = 'weather__content_tab current').
- find('div', class_ = 'weather__content_tab-temperature').
- text.split())
- descr = html.find('div', class_ = 'weather__article_description-text').text
- res_by = '%s %s' % (temp, descr)
- except Exception as err:
- print('error get weather from .com.by site')
- pass
- res = res_ua or res_by
- if not res:
- return ('не найдена погода для города "%s"' % city)
- else:
- return res
- res = get_weather('Гродно')
- print(res)
Add Comment
Please, Sign In to add comment