I am unable to identify correct class name for web scraping for https://peachmode.com/pages/search?q=bags
#importing the required libraries
from bs4 import BeautifulSoup
import requests
import re
import pandas as pd
#Downloading the imdb top rated 100 Indian movie's data
url_link = 'https://peachmode.com/search?q=bags'
response = requests.get(url_link)
soup = BeautifulSoup(response.text)
soup
# creating empty lists to store the data
product_names = []
prices = []
discounts = []
bag_item = soup.find_all('div',class_='anchor wizzy-main-content')
# iterating over each bag
for bag in bag_item:
#product_title
title = bag.find('div',class_='product-title').text.strip()
product_names.append(title)
#price
price = bag.find('div',class_='st-product-prices').text.strip()
prices.append(price)
#discounts
discount = bag.find('span',class_='tag sale').text.strip()
discounts.append(discount)
#creating DataFrame
df = pd.DataFrame({'Product_title':product_names, 'Price':prices, 'Discount':discounts})
print(df)
I was expecting to get title, price, and discount, but I am getting an empty dataframe. Please guide where I am getting wrong; what will be the correct class name?
New contributor
Anubhav Chatterji is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1