Web-Scrapping in Python

Web-Scrapping overview

Why Web-Scrapping is used?

What is Web-Scrapping ?

How would you find web-scraping is legal or not?

How Do You Scrape Data From A Website?

Libraries Used:

Now, let’s get started.

Overview of page
Inspect page
Find Hotel name in inspect page.
Locate inside which the hotel name is stored.
import requests
from bs4 import BeautifulSoup as soup
import pandas as pd
html = requests.get('https://www.tripadvisor.com/Hotels-g297608-Ahmedabad_Ahmedabad_District_Gujarat-Hotels.html')
print(html.status_code)
hotel = []
for name in bs_object.findAll('div',{'class':'listing_title'}):
hotel.append(name.text.strip())
print(hotel)
ratings = []
for rating in bs_object.findAll('a',{'class':'ui_bubble_rating'}):
ratings.append(rating['alt'])
print(ratings)
reviews = []
for review in bs_object.findAll('a',{'class':'review_count'}):
reviews.append(review.text.strip())
print(reviews)
price = []
for p in bs_object.findAll('div',{'class':'price-wrap'}):
price.append(p.text.replace('₹','').strip())
print(price)
d1 = {'Hotel':hotel,'Ratings':ratings,'No_of_Reviews':reviews,'Price':price}
df = pd.DataFrame.from_dict(d1)
print(df)
df.to_csv('hotels.csv', index=False, encoding='utf-8')

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store