how to get all image url and store in list
how to remove ₹ in all element of list using replace command and store in list
Write a python program to scrape mentioned details from dineout.co.inand make data framei) Restaurant name
ii) Cuisine
iii) Location
iv) Ratings
v) Image URL
step 1 first install libraries
pip install bs4
pip install request
step 2 import libraries
from bs4 import BeautifulSoup
import requests
step3:Send an HTTP GET request to the URL and (status code 200)
page = requests.get('https://www.dineout.co.in/delhi-restaurants')
page
output
<Response [200]>
step4: check page content
soup= BeautifulSoup(page.content)
soup
output
step5: get all the element of specific class
data = soup.find_all('div', class_="restnt-info cursor")
data
output
step6: get all restaurant title of specific class and store in list
restaurant_title=[]
for i in data:
restaurant_title.append(i.text)
restaurant_title
step7: get all restaurant location of specific class and store in list
restaurant_location=[]
for i in soup.find_all('div', class_="restnt-loc ellipsis"):
restaurant_location.append(i.text)
restaurant_location
output
step7: get all restaurant price of specific class and store in list
how to remove ₹ in all element of list using replace command and store in list
restaurant_price=[]
for i in soup.find_all('span', class_="double-line-ellipsis"):
restaurant_price.append(i.text.replace('₹',''))
restaurant_price
output
step7: get all restaurant image url of specific class and store in list
**how to get all image url and store in list**
restaurant_images=[]
for i in soup.find_all('img', class_="no-img"):
restaurant_images.append(i['data-src'])
restaurant_images
output
import pandas as pd
df= pd.DataFrame({'title':restaurant_title,'location':restaurant_location,'price':restaurant_price,'image':restaurant_images})
df
output
Top comments (0)