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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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
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