Guest User

Avg GPA

a guest
Apr 9th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import urllib
  2. from BeautifulSoup import BeautifulSoup
  3. import time                                             #Hidden some info to prevent doxxing
  4.  
  5. usnlst = []
  6. for i in range(66,127):
  7.     if i == 110: continue                               #Makes a list of usn's from 066 to 126
  8.     if i < 100:
  9.         usnlst.append('usn'+str(i))
  10.     else:
  11.         usnlst.append('usn'+str(i))
  12.        
  13.  
  14.  
  15. sumgpa = 0.0
  16.  
  17. for usn in usnlst:
  18.     url = 'University- website'
  19.     url = url + usn  #Gives the result url for that usn
  20.     urlh = urllib.urlopen(url)  
  21.     data = urlh.read()      #Reads the html file of the results page
  22.     soup = BeautifulSoup(data)  #Creates a BeautifulSoup object of the html file
  23.     gpa = float(soup.find(id = "lblSGPA").b.string)
  24.     sumgpa += gpa
  25.     print usn + '  ' + str(gpa)
  26.     time.sleep(1)
  27.    
  28. avggpa = sumgpa/float(len(usnlst))
  29. print "Average gpa is: %.2f" %(avggpa)      #Prints average gpa of class
Add Comment
Please, Sign In to add comment