PYTHON CODE:
import requests
from bs4 import BeautifulSoup
class Temperature(object):
def __init__(self, place):
self.place = place
def __repr__(self):
temperature = self.weather()
return str(f"its currently {temperature} in {self.place}")
def weather(self):
url = f"https://www.google.com/search?&q=weather in {self.place}"
req = requests.get(url)
scrape = BeautifulSoup(req.text, "html.parser")
temperature = scrape.find("div", class_="BNeawe").text
return temperature
if __name__ == "__main__":
print(Temperature("delhi"))
OUTPUT:

It would be more functional if a rest API is used so that we get directly a json file of everything and it would be a lot more convinient to represent it in a desirable manner be it graph like or map like as shown in news studios rather than just relying upon a url based feed and then scraping them extensively
ReplyDelete