我使用Python3.3并请求2.2.1。
我试图发布到一个以.jsp结尾的网站,然后更改为.doh ending。使用相同的基本请求代码大纲,我能够成功地登录和刮除其他网站,但是这个站点上的javascript部分不起作用。这是我的密码:
import requests
url = 'https://prodpci.etimspayments.com/pbw/include/sanfrancisco/input.jsp'
payload = {'plateNumber':'notshown', 'statePlate':'CA'} #tried CA and California
s = requests.Session() #Tried 'session' and 'Session' following different advice
post = s.post(url, data=payload)
r = s.get('https://prodpci.etimspayments.com/pbw/include/sanfrancisco/input.jsp')
print(r.text)最后,当通过firefox手动将数据输入网页时,页面会发生变化,url变成https://prodpci.etimspayments.com/pbw/inputAction.doh,只有在键入车牌后才会重定向到该页面。
从打印的文本中,我知道我正在从页面中获得内容,因为它没有POSTing任何内容,但是我需要页面的内容,一旦我获得了POSTed的有效负载。对于POST有效负载,是否需要包含类似“submit”:“submit”之类的内容来模拟单击搜索按钮?
考虑到我发到的网址,我是否在做从正确的网址得到的请求?
发布于 2014-07-16 06:14:10
您正在发出POST请求,然后是另一个GET请求,这就是您使用表单获得相同页面的原因。
response = s.post(url, data=payload)
print(response.text)另外,如果您检查表单标记,您会发现它的操作是/pbw/inputAction.doh,并且表单还会从hidden输入中发送一些参数。因此,您应该在请求中使用该URL,并可能使用来自hidden输入的值。

使用下一段代码,我可以在浏览器中通过常规请求检索相同的响应:
import requests
url = 'https://prodpci.etimspayments.com/pbw/inputAction.doh'
payload = {
'plateNumber': 'notshown',
'statePlate': 'CA',
'requestType': 'submit',
'clientcode': 19,
'requestCount': 1,
'clientAccount': 5,
}
s = requests.Session()
response = s.post(url, data=payload)
print(response.text)在浏览器中,您可以通过表单在相同请求之后看到相同的内容:
...
<td colspan="2"> <li class="error">Plate is not found</li></td>
...https://stackoverflow.com/questions/24772500
复制相似问题