当您点击"我同意"时,我试图通过模仿POST数据来绕过此页面http://casesearch.courts.state.md.us/casesearch/。我已经能够用PHP做到这一点但由于某种原因我无法在Python中重新创建请求。尽管发送了正确的POST数据,但响应始终是包含免责声明的页面。我想要登陆的页面的标题是"马里兰州司法机构案例搜索标准"。我使用的是Python 3。
url = "http://casesearch.courts.state.md.us/casesearch/"
postdata = parse.urlencode({'disclaimer':'Y','action':'Continue'})
postdata = postdata.encode("utf-8")
header = {"Content-Type":"application/x-www-form-urlencoded"}
req = request.Request(url,data=postdata,headers=header)
res = request.urlopen(req)
print(res.read())
答案 0 :(得分:1)
您希望发布到的网址实际上是http://casesearch.courts.state.md.us/casesearch/processDisclaimer.jis
。试试这个:
url = "http://casesearch.courts.state.md.us/casesearch/processDisclaimer.jis"
postdata = parse.urlencode({'disclaimer':'Y','action':'Continue'})
postdata = postdata.encode("utf-8")
header = {"Content-Type":"application/x-www-form-urlencoded"}
req = request.Request(url,data=postdata,headers=header)
res = request.urlopen(req)
print(res.read())