WEATHER
FORECASTING
J.N.V. KIRTANPUR BAHRAICH
SESSION 2023-24
DIRECTED BY :
SANJAY KUMAR PATHAK
DEVLOPED BY:
PRASHANT GAUTAM
RAGHVENDRA SINGH RANA
MUKESH KUMAR
TEAM:
WEATHER
FORECASTING
A PYTHON PROJECT
[Link]
We know weather updates are how
much important in our day-to-day life.
So, We are introducing the logic and
script with some easiest way to
understand for everyone. Let’s see a
simple Python script to show the live
update for Weather information.
MODULES NEEDED:
REQUIRED MODULES:
pip install beautifulsoup4
Beautiful Soup is a Python library that helps us scrape and
extract data from websites by parsing HTML or XML
documents. It's used for navigating, searching, and
manipulating web page elements, making it a valuable tool
for web scraping tasks.
pip install request
The requests library in Python is used to send HTTP
requests to web servers and retrieve data from websites or
interact with web services and APIs. It simplifies web
communication and allows you to access web content, send
data, and handle various web-related tasks.
IMPORT MODULES
After installation we will import all
modules that is essential for this
programming.
USER-AGENT HEADER:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT
10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/58.0.3029.110 Safari/537.3'}:
Sets a User-Agent header to mimic a legitimate
browser and avoid potential anti-scraping
measures.
Note: We will change this header for particular
device.
WEATHER() FUNCTION:
def weather(city):
• Defines a function name
weather that takes the city name as an argument.
city=[Link](" ","+"):
•Replaces spaces in the city name with plus signs to
make the search query URL-friendly.
res =
[Link](f'[Link]
{city}&oq=
{city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&
sourceid=chrome&ie=UTF-8',headers=headers):
•Sends an HTTP GET request to Google Search
using the specified city name and headers.
print("Searching......\n"):
• Displays a "Searching..." message.
soup = BeautifulSoup([Link],'[Link]'):
•Parses the HTML content of the response using
BeautifulSoup.
location = [Link]('#wob_loc')
[0].getText().strip():
•Extracts the location from the HTML element with
the ID 'wob_loc'.
time = [Link]('#wob_dts')[0].getText().strip():
• Extracts the time from the HTML element with the
ID 'wob_dts'.
info = [Link]('#wob_dc')[0].getText().strip():
•Extracts the weather information from the HTML
element with the ID 'wob_dc'.
print(location):#• Prints the extracted
location.
print(time):# •Prints the extracted time.
print(info): #•Prints the extracted weather
information.
print(weather+"°C"): #•Prints the extracted
temperature along with the degree Celsius
symbol.
USER INPUT AND FUNCTION CALL:
city=input("Enter the Name of Any City >> "): Prompts the
user to enter a city name and stores it in the city variable.
city=city+" weather": Appends " weather" to the city
name to form the complete search query.
weather(city): Calls the weather() function with the
modified city name as an argument.
# This code effectively extracts and
displays weather information for
the specified city using
BeautifulSoup and Google Search.
WHOLE CODE:
OUTPUT:
OUTPUT 01 (BAHRAICH )
OUTPUT 02 (SRAWASTI)
OUTPUT 03 (BALLIA)
WEATHER ON : 09 NOV 2023 @5PM
A NKYO U
T H
TEAM
THIS SIDE