ajlaj25
ajlaj25

Reputation: 227

Python HTML POST with requests

I would like to download some weather information with python from: http://idojarasbudapest.hu/archivalt-idojaras, but I can not see the necessary informations until I don't press the submit button "Mehet". There is two information which I have to submit: Year ('ev'), and month ('ho').

As I understand, I have to POST a request with two parameters: 'ev' and 'ho', then the website should "send me" the requested informations.

The following code which I wrote, prints the original website's html code, not the requested one.

import requests

data= {'ev': '2016','ho': 'Január'}
r = requests.post('http://idojarasbudapest.hu/archivalt-idojaras', data=data)

print (r.text)

The html form looks like this:

The html form

Any idea, how to fix this? Thanks for any answer or suggestion.

Upvotes: 3

Views: 1201

Answers (2)

Luke
Luke

Reputation: 774

To your payload, add 'button': 'Mehet'.

data= {'ev': '2016', 'ho': '01', 'button': 'Mehet'}

Upvotes: 2

Odysseas
Odysseas

Reputation: 1060

From inspecting the post request sent by the browser when the "Mehet" button is pressed, I see that the arguments sent in the POST request have a different form than the ones you are posting via requests.

Firefox developer tools screenshot -- http://idojarasbudapest.hu/archivalt-idojaras

So perhaps change your code to something like this:

import requests

data= {'ev': '2016','ho': '01', 'button': 'Mehet'}
r = requests.post('http://idojarasbudapest.hu/archivalt-idojaras', data=data)

print (r.text)

Upvotes: 5

Related Questions