How to Scrape Web Data from Google using Python?

Prerequisites: Python Requests, Implementing Web Scraping in Python with BeautifulSoup

Web scraping is a technique to fetch data from websites. While surfing on the web, many websites don’t allow the user to save data for personal use. One way is to manually copy-paste the data, which both tedious and time-consuming. Web Scraping is the automation of the data extraction process from websites.

In this article, we will scrape the weather update from google’s search result.

Modules Requisred

  • BeautifulSoup: This module is used for iterating, searching, and modifying the parse tree over the HTML or XML parser. To download it type the below command in the terminal.
    pip install beautifulsoup4
  • Requests: Requests library is one of the integral part of Python for making HTTP requests to a specified URL. To download it type the below command in the terminal.
    pip install requests

Below is the implementation.

filter_none

edit
close

play_arrow

link
brightness_4
code

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)

chevron_right


Output :

python-weather-data-web-scraping

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.