I am doing a curl post request to a service:
curl -v --data "cp4=2765&cp3=350&method%3AsearchPC2=Procurar" https://www.ctt.pt/feapl_2/app/open/postalCodeSearch/postalCodeSearch.jspx
I can see that it successful because we have a div with the results in the response body:
...
<div class="highlighted-result text-left">
<h4 class="subheader">Rua Sacadura Cabral</h4>
<h4 class="subheader">Ímpares de 11 a 233</h4>
<h3 class="subheader">Galiza</h3>
<h2>2765-350 ESTORIL</h2>
</div>
...
The wired thing is that if I do it with python + requests, it doesn't give me the expected result as the curl above does, I even tried to set the user agent to the same as curl:
import requests as r
headers_p = {
'User-Agent': 'curl/7.47.0',
'Host': 'www.ctt.pt'
}
payload = {'cp4': 2765, 'cp3': 350, 'method':'', 'searchPC2': 'Procurar'}
req_p = r.post('https://www.ctt.pt/feapl_2/app/open/postalCodeSearch/postalCodeSearch.jspx', data=payload)
print(req_p.text) # doesn't have the the same content as the curl, I need the html block above
But it fails, the server doesn't send me the results html block
headers = {'Content-Type': 'application/xml'}use this snippet and pass this as part ofr.postasheaders=headers. See if you are getting output.Content-Type: application/x-www-form-urlencodedon the request headerpython3also. I can see some data. But not seeing specific html content as part of result. My python version isPython 3.4.3, installed in venv.