Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Mar 3, 2021
Embed
What would you like to do?
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
my_url="https://www.flipkart.com/search?q=samsung+mobiles&sid=tyy%2C4io&as=on&as-show=on&otracker=AS_QueryStore_HistoryAutoSuggest_0_2&otracker1=AS_QueryStore_HistoryAutoSuggest_0_2&as-pos=0&as-type=HISTORY&as-searchtext=sa"
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
containers = page_soup.findAll("div", { "class": "_3O0U0u"})
container = containers[0]
price = container.findAll("div", {"class": "col col-5-12 _2o7WAb"})
ratings = container.findAll("div", {"class": "niH0FQ"})
filename = "products.csv"
headers = "Product_Name, Pricing, Ratings \n"
f.write(headers)
for container in containers:
product_name = container.div.img["alt"]
price_container = container.findAll("div", {"class": "col col-5-12 _2o7WAb"})
price = price_container[0].text.strip()
rating_container = container.findAll("div", {"class": "niH0FQ"})
rating = rating_container[0].text
print("Product_Name:"+ product_name)
print("Price: " + price)
print("Ratings:" + rating)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment