Oh Snap!

Please turnoff your ad blocking mode for viewing your site content

Hit enter after type your search item

Python 3 Web Scrape Live Google Weather API Data By City Name in Command Line Script Using BeautifulSoup4 Library Full Project For Beginners

/
/
/
19 Views

 

Welcome folks today in this post we will be scraping live weather data from google in command line using beautifulsoup4 library in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install bs4

 

After installing this library make an app.py file and copy paste the following code

 

app.py

 

 

import requests 
from bs4 import BeautifulSoup 

# Enter the City Name 
city = input("Enter the City Name: ") 
search = "Weather in {}".format(city) 

# URL 
url = f"https://www.google.com/search?&q={search}"

# Sending HTTP request 
req = requests.get(url) 

# Pulling HTTP data from internet 
sor = BeautifulSoup(req.text, "html.parser") 

# Finding temperature in Celsius 
temp = sor.find("div", class_='BNeawe').text 

print(temp)

 

 

Now if you execute the python script by typing the below command as shown below

READ  Python 3 Script to Convert XML to CSV File Using Pandas and Element Tree Library Full Tutorial For Beginners

 

python app.py

 

 

Now as you can see in the command line as soon we execute the script it ask for the city name we enter london and it returns the live temperature of 13 degree

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar
Coding Shiksha 2020. All Rights Reserved.
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :