[英]Simulating HTTP post request using requests module is not working
I tried to retrieve a page after submitting the form in the following link (with default options):https://selfservice.pasadena.edu/prod/pw_psearch_sched.p_search在以下链接(使用默认选项)提交表单后,我尝试检索页面:https://selfservice.pasadena.edu/prod/pw_psearch_sched.p_search
I realized that the form is post method, so I used requests module to simulate a post request.我意识到表单是post方法,所以我使用requests模块来模拟一个post请求。
r = requests.post(URL, data=form_data).text
For the form data, I extracted using chrome developer tool.对于表单数据,我使用 chrome 开发工具提取。
form_data = {
'TERM': '202070',
'TERM_DESC': 'Fall 2020',
'sel_subj': 'dummy',
'sel_day': 'dummy',
'sel_schd': 'dummy',
'sel_camp': 'dummy',
'sel_ism': 'dummy',
'sel_sess': 'dummy',
'sel_instr': 'dummy',
'sel_ptrm': 'dummy',
'sel_attrib': 'dummy',
'being_hh': '5',
'begin_mi': '0',
'begin_ap': 'a',
'end_hh': '11',
'end_mi': '0',
'end_ap': 'p',
'aa': 'N',
'bb': 'N',
'ee': 'N'
}
But it keeps giving me 404 Error
.但它一直给我
404 Error
。
At first, I tried to use selenium
to simulate clicking the submit button but it is way too slow.起初,我尝试使用
selenium
来模拟点击提交按钮,但速度太慢了。
Any help would be appreciated.任何帮助,将不胜感激。
There are two problems有两个问题
form sends to different url: https://selfservice.pasadena.edu/prod/pw_psearch_sched.p_listthislist表格发送到不同的 url: https://selfservice.pasadena.edu/prod/pw_psearch_sched.p_listthislist
small mistake in name 'begin_hh'
- you have 'being_hh'
名称
'begin_hh'
中的小错误 - 你有'being_hh'
Working code工作代码
import requests
data = {
'TERM': '202070',
'TERM_DESC': 'Fall 2020',
'sel_subj': 'dummy',
'sel_day': 'dummy',
'sel_schd': 'dummy',
'sel_camp': 'dummy',
'sel_ism': 'dummy',
'sel_sess': 'dummy',
'sel_instr': 'dummy',
'sel_ptrm': 'dummy',
'sel_attrib': 'dummy',
'sel_crse': '',
'sel_crn': '',
'sel_title': '',
'begin_hh': '5',
'begin_mi': '0',
'begin_ap': 'a',
'end_hh': '11',
'end_mi': '0',
'end_ap': 'p',
'aa': 'N',
'bb': 'N',
'ee': 'N',
}
URL = 'https://selfservice.pasadena.edu/prod/pw_psearch_sched.p_listthislist'
r = requests.post(URL, data=data)
print(r.status_code)
#print(r.text)
BTW: originally form sends two values for some fields and it would be顺便说一句:最初表单为某些字段发送两个值,它将是
'sel_subj': ['dummy', '%'],
'sel_day': 'dummy',
'sel_schd': ['dummy', '%'],
'sel_camp': ['dummy', '%'],
'sel_ism': ['dummy', '%'],
'sel_sess': ['dummy', '%'],
'sel_instr': ['dummy', '%'],
'sel_ptrm': ['dummy', '%'],
'sel_attrib': ['dummy', '%'],
but page works even if you send one value.但是即使您发送一个值,页面也可以工作。
BTW: in DevTool
you can get code for rpogram curl
and later you can convert it to Python code using page https://curl.trillworks.com/顺便说一句:在
DevTool
中,您可以获得 rpogram curl
的代码,稍后您可以使用页面https://curl.com将其转换为 Python 代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.