Sample WebScraping

########### Source code for webscraping ############

from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
driver = webdriver.Chrome("/home/ranjith/Documents/Software/Chrome/chromedriver_linux64/chromedriver")
products=[] #List to store name of the product
prices=[] #List to store price of the product
driver.get("https://www.flipkart.com/laptops/~buyback-guarantee-on-laptops-/pr?sid=6bo%2Cb5g&uniq")
content = driver.page_source
soup = BeautifulSoup(content)
for a in soup.findAll('a', attrs={'class':'_31qSD5'}):
    name=a.find('div', attrs={'class':'_3wU53n'})
    price=a.find('div', attrs={'class':'_1vC4OE _2rQ-NK'})
    rating=a.find('div', attrs={'class':'hGSR34 _2beYZw'})
    try:
        products.append(name.text)
    except:
        products.append("-----")
    try:
        prices.append(price.text)
    except:
        prices.append('-----')
df = pd.DataFrame({'Product Name':products,'Price':prices}) 
print(df)

######## OUTPUT ###########

                                        Product Name    Price
0  Apple MacBook Air Core i5 5th Gen - (8 GB/128 ...  ₹67,990
1  HP 15 Core i3 6th Gen - (4 GB/1 TB HDD/Windows...  ₹28,997
2  Apple MacBook Air Core i5 5th Gen - (8 GB/256 ...  ₹92,500
3  Lenovo Core i5 7th Gen - (8 GB/1 TB HDD/DOS/2 ...  ₹52,990
4  Lenovo Core i3 6th Gen - (4 GB/1 TB HDD/Window...  ₹30,550
5  Lenovo Ideapad Core i3 6th Gen - (4 GB/1 TB HD...  ₹32,990
6  Lenovo Core i5 7th Gen - (8 GB/2 TB HDD/Window...  ₹75,500