Check CBSE result using Selenium in Python

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.
- Candidate name
- Pass or fail status
- Marks obtained
Installations requiredÂ
- Go to command prompt and put this is in:
pip install selenium
- Once that’s done, download a webdriver for automation. Here, we’ll use chromedriver from http://chromedriver.chromium.org/
Approach:
- First to go 12th website follow this LINK(this is for CBSE board 12th result 2014 pass-out).
- Then click on investigate element by urgent ctrl + shift + I or stepping into setting of browser and clicking on investigate detail manually.
- Then navigate to the box where the roll number is filled then copy the x_path.
- Then navigate the view submit button then copy the x_path.
- 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 webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import Selectfrom selenium.common.exceptions import NoSuchElementExceptionimport csvimport timeÂ
Â
# creating csv filefilename = "cbse.csv"Â
# open csv file to writef = open(filename, 'w')Â
# create header in fileheader = "NAME,STATUS,NUM\n"f.write(header)Â
# put range of rollnumberfor 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(            "http://resultsarchives.nic.in/cbseresults/cbseresults2014/class12/cbse122014_total.htm")Â
        # 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:



