Last active
August 29, 2015 14:09
-
-
Save benfulton/16e987403cdba941174a to your computer and use it in GitHub Desktop.
Screen scraper to summarize grades for MyStudentsProgress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from lxml import html | |
courseids=[62454,62508,62446,62557,62448,62513,62549,62511,62451,62558,62477] | |
# music 62531, | |
def grade(r): | |
try: | |
return float(r[2][0])/float(r[2][1]) | |
except ValueError: | |
return 0 | |
url = 'https://indianapolis.mystudentsprogress.com/MSP/index.cfm?fuseaction=parent.assign_list&student_id=40163&quarter_id=1408&course_id=' | |
s = requests.Session() | |
s.get('https://indianapolis.mystudentsprogress.com/MSP/index.cfm') | |
payload = {'email': 'EMAIL', 'password': 'PASSWORD'} | |
r = s.post("https://indianapolis.mystudentsprogress.com/MSP/index.cfm?fuseaction=home.loginAction", data=payload) | |
results = [] | |
for c in courseids: | |
r = s.get(url + str(c)) | |
tree = html.fromstring(r.text) | |
trs = tree.xpath('//table[@class="list"]/tr') | |
for tr in trs[1:-1]: | |
c = tr.getchildren() | |
results.append((c[0].text,c[2].getchildren()[0].text.strip(),c[4].text.strip().split('/'))) | |
for r in sorted(results, key=grade): | |
print '%s,"%s",%s,%s' % (r[0], r[1], r[2][0], r[2][1]) | |
#print '%s: "%s" %s out of %s' % (r[0], r[1], r[2][0], r[2][1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment