Open In App

Check 12th Class Result Using Selenium in Python

Last Updated : 25 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

We are going to collect the data of 12th class in CSV file with the following information:

  1. Candidate name
  2. Pass or fail status
  3. Division
  4. Obtain marks

This task will be done by using selenium library of Python.

Requirement:

You need to install chrome driver and set path. Click here To download. For more information follow this link. 

Approach:

  1. First to go 12th website follow this LINK(this is for up board 12th result).
  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 district is select then copy the x_path.
  4. Then navigate to the box where the roll number is filled then copy the x_path.
  5. Then navigate the view result button then copy the x_path.
  6. I want to store the result in CSV file then also navigate student name, fail-pass status, division, obtain marks. Then fill up roll number automatically by script go to next page find x_path of student name, fail-pass status, division, obtain marks.

Follow step-by-step with the help of screenshots and copy the x_path of element and put into the code:

Step 1:

Step 2:

Step 3:

Step 4:

Step 5:

Step 6:

Step 7:

Step 8:

Step 9:

Step 10:

Step 11:

Step 12:

Below is the implementation:

Python3
# import required libraries
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
 
# give name of csv file
filename = "abc.csv"

# open file in write mode
f = open(filename, 'w')

# create header in file
header = "NAME,STATUS,DIV,NUM\n"

# write into the file
f.write(header)

# put rollnumber without zero like
# your number 0477593 then
# put 477593 upto XXXXX.
start_rollNum = 926840
end_rollNum = 926841

# put range of rollnumber
for i in range(start_rollNum, end_rollNum ):
  
    # use try and except 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("https://results.upmsp.edu.in/ResultIntermediate.aspx")
        
        # add zero in rollnumber in starting
        t = '0' + str(i)
        
        # district xpath
        state = driver.find_element_by_xpath('//*[@id="ctl00_cphBody_ddl_districtCode"]')
        drp1 = Select(state)
        
        # select district
        drp1.select_by_visible_text('LUCKNOW')
        
        # put rollnumber
        driver.find_element_by_xpath('//*[@id="ctl00_cphBody_txt_RollNumber"]').send_keys(t)
        
        # view result xpath
        driver.find_element_by_xpath('//*[@id="ctl00_cphBody_btnSubmit"]').click()
        
        # student name
        name = driver.find_element_by_xpath('//*[@id="ctl00_cphBody_lbl_C_NAME"]').text
        
        # status pass or fail
        status = driver.find_element_by_xpath('//*[@id="ctl00_cphBody_lbl_RESULT"]').text
        
        # division
        div = driver.find_element_by_xpath('//*[@id="ctl00_cphBody_lbl_DIVISION"]').text
        
        # obatin marks
        num = driver.find_element_by_xpath('//*[@id="ctl00_cphBody_lbl_MRK_OBT"]').text
        
        # all details fill into csv file
        f.write(name + "," + status + "," + 
                div[1 : ] + "," + num + "\n")
        
        # close the driver
        driver.close()
        
    except NoSuchElementException as exception:
        continue

# close and save the file
f.close()

Output:

CSV file screenshot

Note: If you Want to find a topper then apply a filter on CSV file.


Next Article

Similar Reads