使用 urllib2 (python) 提交搜索表单
我正在尝试在学校系统中搜索课程,并使用我的登录信息进行登录
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)
尝试查找课程不起作用,这是我所拥有的
# 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()
这是我所看到的
https://i.sstatic.net/nmk0C.jpg
这是如果正确完成的话应该出现的内容
https://i.sstatic.net/BSOuJ.png
(还无法发布图像..)
我的搜索表单做错了什么?
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
Here is what I see
https://i.sstatic.net/nmk0C.jpg
Here is what is supposed to appear if done correctly
https://i.sstatic.net/BSOuJ.png
(can't post images yet..)
What am I doing wrong with the search form?
: '575', 'CLASS_SRCH_WRK2_SUBJECT$69
Here is what I see
https://i.sstatic.net/nmk0C.jpg
Here is what is supposed to appear if done correctly
https://i.sstatic.net/BSOuJ.png
(can't post images yet..)
What am I doing wrong with the search form?
:'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.sstatic.net/nmk0C.jpg
Here is what is supposed to appear if done correctly
https://i.sstatic.net/BSOuJ.png
(can't post images yet..)
What am I doing wrong with the search form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
urllib2.Request()
的第二个参数是POST
数据,而不是GET
查询字符串。您可以通过将查询字符串直接附加到 URL 来发送:The second argument to
urllib2.Request()
is thePOST
data, not theGET
query string. You can send the query string by directly attaching it to the URL: