Skip to content
Related Articles

Related Articles

Improve Article

Check CBSE result using Selenium in Python

  • Last Updated : 04 Jan, 2021

Prerequisite: Selenium Python

In this article, we will scrape the CBSE result from their website and store the result in a CSV file. The CSV file will contain the following information.

  1. Candidate name
  2. Pass or fail status
  3. Marks obtained

Installations required 

  • Go to command prompt and put this is in:
pip install selenium

Approach:

  1. First to go 12th website follow this LINK(this is for CBSE board 12th result 2014 pass-out).
  2. Then click on investigate element by urgent ctrl + shift + I or stepping into setting of browser and clicking on investigate detail manually.
  3. Then navigate to the box where the roll number is filled then copy the x_path.
  4. Then navigate the view submit button then copy the x_path.
  5. We want to store the result in CSV file then also navigate student name, fail-pass status, marks obtained and then fill up roll number automatically by script go to next page find x_path of student name, fail-pass status, obtain marks.

Given some screenshot to follow this instruction step by step:

Step 1:



Step 2:

Step 3:

Step 4:

Step 5:



Step 6:

follow same left three subject

Below is the implementation:

Python3




from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import csv
import time
  
  
# creating csv file
filename = "cbse.csv"
  
# open csv file to write
f = open(filename, 'w')
  
# creat header in file
header = "NAME,STATUS,NUM\n"
f.write(header)
  
# put range of rollnumber
for i in range(9639428, 9639432):
      
    # use try and exception because if any
    # rollnumber is invalid then whole
    # program is not stop.
    try:
        driver = webdriver.Chrome()
          
        # link is given above copy and paste
        driver.get(
  
        # put rollnumber
        driver.find_element_by_xpath(
            '/html/body/table[3]/tbody/tr/td/font/center[2]/form/div[1]/center/p/input[1]').send_keys(i)
          
        # view result xpath
        driver.find_element_by_xpath(
            '/html/body/table[3]/tbody/tr/td/font/center[2]/form/div[1]/center/p/input[2]').click()
          
        # student name
        name = driver.find_element_by_xpath(
            '/html/body/div[2]/table[2]/tbody/tr[2]/td[2]/font/b').text
          
        # status pass or fail
        status = driver.find_element_by_xpath(
            '/html/body/div[2]/div/center/table/tbody/tr[12]/td[2]/b[1]/font').text
          
        # first subject find xpath then next 4 subject
        m1 = driver.find_element_by_xpath(
            '/html/body/div[2]/div/center/table/tbody/tr[2]/td[5]/font').text
        m2 = driver.find_element_by_xpath(
            '/html/body/div[2]/div/center/table/tbody/tr[3]/td[5]/font').text
        m3 = driver.find_element_by_xpath(
            '/html/body/div[2]/div/center/table/tbody/tr[4]/td[5]/font').text
        m4 = driver.find_element_by_xpath(
            '/html/body/div[2]/div/center/table/tbody/tr[5]/td[5]/font').text
        m5 = driver.find_element_by_xpath(
            '/html/body/div[2]/div/center/table/tbody/tr[6]/td[5]/font').text
          
        # sum all marks
        num = str(int(m1)+int(m2)+int(m3)+int(m4)+int(m5))
  
        # all details fill into file
        f.write(name+","+status[9:]+","+num+"\n")
        driver.close()
      
    except NoSuchElementException as exception:
        continue
  
f.close()

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :