Rohan Anand
Rohan Anand


Rohan Anand

Web Scrapping demo project

Web Scrapping demo project

Rohan Anand's photo
Rohan Anand
·Dec 20, 2022·

1 min read

Table of contents

  • Introduction
  • Codes


In this project, I'm going to show you my web scrapping project which is of course very small but will give you an insight into web scrapping.

I've done web scrapping over a FlipKart item (hp Pavillion laptop), you can choose your own, using some libraries and making a function for it.


>>> from bs4 import BeautifulSoup
    import requests
    import datetime
    import csv

>>> def myscrap():
      URL = ''

       # use '' to get your User Agent
      headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36", "Accept-Encoding":"gzip, deflate", "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "DNT":"1","Connection":"close", "Upgrade-Insecure-Requests":"1"}

      # requests is used to get the information about page from urls
      page = requests.get(URL, headers=headers)
      s = BeautifulSoup(page.content, "html.parser")
      # after printing 's' you will get distorted data which isn't readable
      # to make it more readable use prettify()
      s1 = BeautifulSoup(s.prettify(), "html.parser")
      mark= s1.find(id='productRating_LSTCOMG67BXZCXUTPG2FKQWDH_COMG67BXZCXUTPG2_').get_text()
      # to make it more clear use strip()
      mark= mark.strip()
      # print(mark)
      today_date =

    # to write all data into a csv file
    header = ['Mark', 'Today-date']  # column headers
      data = [mark, today_date]
      with open('flipkartwebscrappedfile.csv', 'w', newline='', encoding='UTF8') as f:
          writer = csv.writer(f)
Share this