处理带有请求的单选按钮

2024-05-20 14:17:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python请求触发单选按钮。你知道吗

当前我正在查看手动选择单选按钮时发生的情况:

XHR收件人:http://exmp-url/admin-ajax.php

标题:

'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'

有效载荷:

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

我尝试用相同的负载和头来模拟和发送数据:

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")

响应的状态码为200,而内容为b'\xef\xbb\xbf',解码后为空。你知道吗

我做错什么了?也许我应该换个方法,试着点击按钮本身。我宁愿不用硒。robobrowser在这里是否没有可见的form元素?你知道吗

选中单选按钮的HTML:

<input type="radio" id="rez_obiekt_typ_t" name="obiekt_typ" data-obiekt_typ="tenis" checked="" value="tenis" class="ui-helper-hidden-accessible">

Tags: httpurldataadminpageajaxcontent按钮