0

I am trying to search for courses in my school's system and logging in works with my login info

import urllib, urllib2, cookielib,re

username = 'user'
password = 'pass'

# Login main site
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'userid' : username, 'pwd' : password})
opener.open('https://psns.cc.stonybrook.edu/psp/he90prods/?cmd=login', login_data)

Trying to find courses does not work, here is what I have

# Fill in Class search criteria
search_data = {'CLASS_SRCH_WRK2_CATALOG_NBR$73$': '575', 'CLASS_SRCH_WRK2_SUBJECT$69$':'AMS'}
request = urllib2.Request('https://psns.cc.stonybrook.edu/psc/he90prods/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.CLASS_SEARCH.GBL', urllib.urlencode(search_data))
response = opener.open(request)
print response.read()

Here is what I see

https://i.stack.imgur.com/nmk0C.jpg

Here is what is supposed to appear if done correctly

https://i.stack.imgur.com/BSOuJ.png

(can't post images yet..)

What am I doing wrong with the search form?

1 Answers1

0

The second argument to urllib2.Request() is the POST data, not the GET query string. You can send the query string by directly attaching it to the URL:

request = urllib2.Request('https://psns.cc.stonybrook.edu/psc/he90prods/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.CLASS_SEARCH.GBL?' + urllib.urlencode(search_data))
Vasiliy Faronov
  • 11,840
  • 2
  • 38
  • 49