-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraber.py
55 lines (42 loc) · 1.8 KB
/
graber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import time
#import selenium.webdriver.support.ui as ui
from selenium import webdriver
class GradeGraber:
def __init__(self):
#self.uniqname = uniqname
#self.password = password
self.url = 'https://csprod.dsc.umich.edu/services/student'
return
def grab(self, uniqname, password, filename):
self.browser = webdriver.Firefox()
#self.browser = webdriver.Chrome()
self.browser.get(self.url)
#wait = ui.WebDriverWait(self.browser, 120) # time out after 10 seconds
self.browser.find_element_by_id('login').send_keys(uniqname)
self.browser.find_element_by_id('password').send_keys(password)
self.browser.find_element_by_id('loginSubmit').click()
#wait.until(lambda driver: self.browser.find_elements_by_id('ptifrmtgtframe'))
self.browser.switch_to_frame('TargetContent')
self.browser.find_element_by_xpath("//a[@title='View an unofficial copy of your academic transcript.']").click()
#wait.until(lambda driver: self.browser.find_elements_by_id('ptifrmtgtframe'))
self.browser.switch_to_frame('TargetContent')
self.browser.find_element_by_id('GO').click()
#wait.until(lambda driver: self.browser.find_element_by_id('ptifrmtgtframe').find_element_by_id('M_SR_TSCRPT_HDR_MESSAGE_PARM1'))
time.sleep(10) # wait for the results to come out
self.browser.switch_to_default_content()
self.browser.switch_to_frame('TargetContent')
#print self.browser.page_source.encode('utf-8')
results = self.browser.find_elements_by_xpath("//*[contains(@id, 'win0divDERIVED_TSCRPT_TSCRPT_COMP_DATA')]")
self.writeFile(results, filename)
self.closeBrowser()
return results
def writeFile(self, results, filename):
transcript = ''
for r in results:
transcript += r.text + '\n'
f = open(filename, 'w')
f.write(transcript)
f.close()
def closeBrowser(self):
self.browser.quit()
return