As part of my ongoing 20-day challenge to build one Python project a day, I’m thrilled to present my 8th project, a Weather App built with Python.
The goal of this challenge is simple: to push myself daily, improve my Python skills, and build a solid portfolio of small but meaningful projects.
In this blog post, I’ll take you through every step I followed to build this app, from library installation to writing and testing the code.
If you're just getting started with Python and want to build something useful and fun, a weather app is a great mini-project. In this post, I’ll walk you through how I built a simple weather app that fetches real-time weather data using web scraping from Google search results. No API keys. No complicated setup. Just Python and a few lines of code!
📦 What You'll Need
Before we dive in, make sure you have the following Python libraries installed:
The Complete Code
Here’s the code and a breakdown of how it works:
1. Import the Libraries
- requests lets me send HTTP requests to websites.
- BeautifulSoup helps to parse and extract data from HTML
2. Define the Search Query
I define the city I want weather data for. You can change "Skopje" to any city like "Weather in New York" or "Weather in Tokyo".
3. Build the Google Search URL
This creates a URL that performs a Google search for the weather.
4. Send the Request
This line fetches the HTML content of the Google search results page.
5. Parse the HTML
I convert the HTML into a structured format using BeautifulSoup so I can search for specific elements.
6. Extract the Weather Info
Google displays the current temperature and weather inside a <div> tag with the class name BNEawe. This line finds that element and extracts the text (like 28°C).
7. Print the Result
Finally, I print the weather update.
Example Output
When you run the script, you might get something like:
Conclusion
You’ve just built a simple weather app using Python, requests, and BeautifulSoup to scrape data directly from Google search. This is a great beginner project to practice web scraping and get comfortable with handling HTML in Python.
▶️ Demo Video
⚠️ A Word of Caution
Google’s page structure can change at any time, and this might break your script. This method is good for quick experiments but not recommended for production apps.
For more stable and legal use cases, consider using a free weather API like:
- OpenWeatherMap
- WeatherAPI
- Weatherstack
0 Comments