WEATHER SCRAPER

 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:



Comments

  1. 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

Post a Comment

Followers

Popular posts from this blog

LOGIN AND REGISTRATION FORM USING HTML/CSS

Contact form

Name

Email *

Message *