iBreaker/bjguahao

挂号失败,post 的 response 是一个 html

coeusite opened this issue · 2 comments

遇到一个BUG,挂号时的 response 不是 json 而是一个 html
bjguahao.py > get_it() > response = self.browser.post(self.confirm_url , data=preload)

尝试测试了一下,结果弄得我自己一头雾水。

在 Chrome 上手动挂号,挂号时同样是

dutySourceId:45004502
hospitalId:122
departmentId:200001019
doctorId:200287869
patientId:**********
hospitalCardId:
medicareCardId:
reimbursementType:-1
smsVerifyCode:763466
childrenBirthday:
isAjax:true
  • 返回值如下:
code:200
data:******
hasError:false
msg:"OK"

用脚本挂同一个号,post 的数据基本一致,除了SMS码和reimbursementType,但返回值的response.text却是个HTML,且挂号不成功。
response.text写入文件后发现是选择时间的那个挂号页。

Chrome 中发送 POST 请求时的 Headers:

POST /order/confirm.htm HTTP/1.1
Host: www.bjguahao.gov.cn
Connection: keep-alive
Content-Length: 202
Origin: http://www.bjguahao.gov.cn
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
DNT: 1
Referer: http://www.bjguahao.gov.cn/order/confirm/122-200001019-200287869-45004502.htm
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2
Cookie: ******

脚本 POST 时的 Headers:

{
'Referer': u'http://www.bjguahao.gov.cn/order/confirm/122-200001019-200287869-45004502.htm', 
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
}

我修改了一下,这个Headers也不好用(response.request.headers)

{
'Accept-Language': 'en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2', 
'Accept-Encoding': 'gzip, deflate', 
'Accept': 'application/json, text/javascript, */*; q=0.01', 
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 
'DNT': '1', 
'Host': 'www.bjguahao.gov.cn', 
'Origin': 'http://www.bjguahao.gov.cn', 
'Referer': u'http://www.bjguahao.gov.cn/order/confirm/122-200001019-200287869-45004502.htm', 
'Cookie': 'SESSION_COOKIE=***; JSESSIONID=***', 
'X-Requested-With': 'XMLHttpRequest'
}

问题解决