Python’s simplicity and adaptability have helped it gain popularity throughout the years.

you could easily retrieve useful data over the internet with Python.

you could then use that data to drive a practical software.

Weather Forecast of cities in a map

Learn how to find real-time weather data using web scraping and APIs.

you might use this fetched data to develop a simple weather app.

Autonomously fetching data from the web opens up a lot of use cases.

chrome screenshot displaying New Delhi weather data scraping

you’re gonna wanna plant the BeautifulSoup Python library via pip to begin the scraping process.

This method runs a CSS selector against the parsed document and returns all the matching elements.

ThegetText()method extracts the text from the HTML element.

New Delhi weather data scraping using python

Thestrip()method removes any leading and trailing whitespace characters from the text.

Once youve extracted a clean value, you’re able to store it in a variable.

You must enter a valid city name to get the results or the code will raise an exception.

OpenWeatherMap My API keys website screenshot

The free tier of the OpenWeatherMap API provides current weather data with a limit of 60 calls/minute.

you gotta create an account on OpenWeatherMap to get your own API key.

In a production app, considermoving the API key data to a .env filefor enhanced security.

New Delhi weather data from OpenWeatherMap API

Go toOpenWeatherMap’swebsite and create a free account.

After creating the account, you might find your API keys on theMy API Keyspage.

OpenWeatherMap provides the support to generate as many API keys as needed for your projects.

Now, you’re ready to retrieve the live weather data.

Building a weather app can help you to apply what you know and hone your Python skills.

Getting your hands dirty on practical projects can make you a better developer.