使用 urllib2 (python) 提交搜索表单

发布于 2024-11-24 14:58:27 字数 1078 浏览 1 评论 0原文

我正在尝试在学校系统中搜索课程,并使用我的登录信息进行登录

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独夜无伴 2024-12-01 14:58:27

urllib2.Request() 的第二个参数是 POST 数据,而不是 GET 查询字符串。您可以通过将查询字符串直接附加到 URL 来发送:

request = urllib2.Request('https://psns.cc.stonybrook.edu/psc/he90prods/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.CLASS_SEARCH.GBL?' + urllib.urlencode(search_data))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文