Skip to content

Instantly share code, notes, and snippets.

@nandini-menon
Created January 17, 2020 14:14
Show Gist options
  • Save nandini-menon/eaad3c8c86effc6c7c23175fe812a9b8 to your computer and use it in GitHub Desktop.
Save nandini-menon/eaad3c8c86effc6c7c23175fe812a9b8 to your computer and use it in GitHub Desktop.
To get the details of all faculties in colleges registered with AICTE
import csv
from selenium import webdriver
from selenium.webdriver.common.by import By
def main():
id_list = list()
name_list = list()
with open('institute_list.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for lines in csv_reader:
id_list.append(lines[0])
name_list.append(lines[1])
f = open('faculty_details.csv', 'w')
driver = webdriver.Chrome()
for college_id in id_list:
index = id_list.index(college_id)
url = 'http://www.knowyourcollege-gov.in/facultyDetails.php?insti_id=' + college_id
driver.get(url)
rows = driver.find_elements_by_xpath('//div[@class="CSSTableGenerator"]/table/tbody/tr')
row_num = len(rows) - 1
for i in range (2, row_num + 1):
name_xpath = '//*[@id="institute-detail"]/div[2]/table/tbody/tr[' + str(i) + ']/td[2]'
email_xpath = '//*[@id="institute-detail"]/div[2]/table/tbody/tr[' + str(i) + ']/td[4]/a'
subject_xpath = '//*[@id="institute-detail"]/div[2]/table/tbody/tr[' + str(i) + ']/td[7]'
name = driver.find_element_by_xpath(name_xpath).text
email = driver.find_element_by_xpath(email_xpath).text
subject = driver.find_element_by_xpath(subject_xpath).text
f.write(name + ', ' + email + ', ' + subject + ', ' + name_list[index] + '\n')
driver.close()
f.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment