Advertisement
Danila_lipatov

Google_weather_parser

Nov 29th, 2023 (edited)
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. """
  2. If it will be helpful, please like this post
  3. """
  4. from bs4 import BeautifulSoup as bs
  5. import requests
  6. import urllib.request
  7. import ssl
  8.  
  9. ssl._create_default_https_context = ssl._create_unverified_context
  10. """
  11. This is basic parser of weather from google
  12. Using:
  13. ----Write to input_box(or to bot if we gonna use telegram)
  14. ----If town(coordinates) is exists: get temperture fot today + describe weather feeling.
  15. ----If town(coordinates) is not exists: don't get tempreture.
  16.  
  17. """
  18. if __name__ == '__main__':
  19.     headers = {
  20.         'User-Agent': ''}
  21.     url = f"https://www.google.com/search?q=погода+в+{str(input())}"
  22.     parser = requests.get(url)
  23.     if parser.status_code == 200:
  24.         soup = bs(parser.text, 'html.parser')
  25.         try:
  26.             temp = soup.find('div', class_='BNeawe iBp4i AP7Wnd').text
  27.             date, status = soup.find('div', class_='BNeawe tAd8D AP7Wnd').text.split('\n')
  28.         except:
  29.             print('Нет данных по такому городу')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement