我对python请求帖有疑问。使用帖子,它仍然返回搜索页面而不是结果页面。
我四处寻找,但我自己无法解决。
我的代码(不包含标题):
url_city_search='http://facilityquality.dads.state.tx.us/qrs/public/qrs.do?page=searchCity&lang=en&mode=P&dataSet=1&ctx=2630332'
data={"serviceTypeOption":"al_B","cityName":"Houston","dispatch":"citySearch"}
s = requests.Session()
providers=s.post(url_city_search,headers=headers,data=data,timeout=15, verify=True)
print providers.status_code
print providers.text
答案 0 :(得分:1)
@sideshowbarker很好地回答了你的问题,但我认为如果你将dict传递给你请求中的可选requests
参数,那么params
将处理为你构建参数字符串也是值得的。 。在自己构建字符串时,很容易弄错参数。
import requests
url_params = {
"page": "qrsSearchResults",
"lang": "en",
"mode": "P",
"dataSet": "1"
}
url_base = "http://facilityquality.dads.state.tx.us/qrs/public/qrs.do"
data = {"serviceTypeOption":"al_B", "cityName":"Houston", "dispatch":"citySearch"}
s = requests.Session()
providers = s.post(url_base, params=url_params, data=data, timeout=15, verify=True)
print providers.status_code
print providers.text