1

I want to trigger radio button with python-requests.

Currently I am looking what is happening when radio button is manually selected:

XHR to: http://exmp-url/admin-ajax.php

HEADERS:

'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7,de;q=0.6',
'Connection': 'keep-alive',
'Content-Length': '110',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'

Payload:

'operacja': 'ShowRezerwacjeTable',
'action': 'ShowRezerwacjeTable',
'data': '2019-03-19',
'obiekt_typ': 'badminton',
'godz_od': '',
'godz_do': ''

I am trying to mimic and send data with the same payload and headers:

with Session() as c:
    c.post(login_page, data=payload)
    # Getting page content after logging in.
    response = c.get(reservation_page)

    content = response.content
    c.headers.update(headers)
    resp = c.post('http://http://exmp-url/admin-ajax.php', data=payload2)
    # Getting new content that should have altered HTML after radio button is checked.
    new_content = codecs.decode(resp.content, encoding="utf-8-sig")

The response's status code is 200 while content is b'\xef\xbb\xbf' and after decoding it's empty.

What am I doing wrong? Maybe I should switch approach and instead try to click on the button itself. I would prefer not to use selenium. Is robobrowser perferred here without the visible form element?

Checked radio button's HTML:

<input type="radio" id="rez_obiekt_typ_t" name="obiekt_typ" data-obiekt_typ="tenis" checked="" value="tenis" class="ui-helper-hidden-accessible">
Kamal
  • 2,384
  • 1
  • 13
  • 25
ap3x
  • 33
  • 7
  • So is it a problem with the decoding or the [requests library](http://docs.python-requests.org/en/master/)? – Nazim Kerimbekov Mar 21 '19 at 00:09
  • I guess you found the XHR request from browser tools, there you can also see the response of the request received by the browser. You can check and confirm if this is the output you should expect from this request or not. If the response is not matching, then it is possible that you missed some important header/payload data. – Kamal Mar 22 '19 at 08:42

0 Answers0