I have a question about python request post. With the post, it still returns the searching page not the result page.
I have searched around, but I couldn't solve it by myself.
my code (headers are not included):
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
lmiguelvargasf
71.3k55 gold badges231 silver badges241 bronze badges
asked Apr 16, 2017 at 23:03
Mingxuan Zhang
111 silver badge3 bronze badges
1 Answer 1
@sideshowbarker answered your question quite well, but I thought it was also worth adding that requests will handle building the parameter string for you if you pass a dict to the optional params argument in your request. It's easy to get the parameters wrong when building the string yourself.
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
answered Apr 18, 2017 at 15:00
etemple1
1,7981 gold badge11 silver badges13 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
sideshowbarker
Good point. Actually, can’t the
data members also being combined with the URL params? They are all just params and values too.etemple1
Yes! I wasn't sure if they were url parameters or form data, but they absolutely can (and should) be added.
lang-py