Dear team,
I want to scrap the flipkart website to fetch the product name, price and ratings. The page i want to scrap contain 24 phones but when i run my code i get one phone item of the 24 phones items. Apparently my code is working very well.
‘’’
import requests
from bs4 import BeautifulSoup
response = requests.get(‘Samsung- Buy Products Online at Best Price in India - All Categories | Flipkart.com’)
content = response.content
parser = BeautifulSoup(content, 'html.parser')
containers = parser.find_all('div', class_ = '_3O0U0u')
container = containers[0]
print(container.div.img['alt'])
price = parser.find_all('div', class_='_1vC4OE _2rQ-NK')
print(price[0].text)
ratings = parser.find_all('div', class_='hGSR34')
print(ratings[0].text)
for container in containers:
product_name = container.div.img['alt']
price_container = parser.find_all('div', class_='_1vC4OE _2rQ-NK')
price = price_container[0].text
rating_container = parser.find_all('div', class_='hGSR34')
rating = rating_container[0].text
print('product_name: ' + product_name)
print('price: ' + price)
print('ratings: '+ rating)'''
What am I doing wrong? How can I modify my code to print the product name, price and rating of the 24 phone in one of the pages
Thanks