简体   繁体   English

在python中发送JavaScript表单数据(发布请求)?

[英]Sending javascript form data in python (post request)?

I'm very new to python and I'm trying to 'select' a radio button that is within a survey on a website. 我对python还是很陌生,我正在尝试“选择”网站调查中的一个单选按钮。 I really have no idea where to start with the python code. 我真的不知道从python代码开始。 I believe the survey is in javascript and when the submit button is clicked, it sends the data to the server running the survey. 我相信调查是使用javascript进行的,并且当单击“提交”按钮时,它将数据发送到运行调查的服务器。 The code I got from the survey radiobutton is as follows 我从调查单选按钮获得的代码如下

<input type="radio" class="sg-input sg-input-radio" name="sgE-1416699-3-2" id="sgE-1416699-3-2-10002" value="10002" title="Name of RadioButton">

The code I have of the submit button is here 我有提交按钮的代码在这里

<input type="submit" class="sg-button sg-submit-button" id="sg_SubmitButton" name="sGizmoSubmitButton" data-domain="www.surveygizmo.com" value="Vote">

Any help on how this is to be done will be greatly appreciated. 对此方法的任何帮助将不胜感激。 Thanks. 谢谢。

Suppose you have these params: 假设您具有以下参数:

sgE-1416699-3-2 = 10002
more_param = param_value

Then prepare: 然后准备:

from urllib import urlopen, urlencode
data = {'sgE-1416699-3-2':'10002', 'more_param':'param_value'}
encodeddata = urlencode(data)
url = 'http://surveygizmo.com'

Now, to make a GET request: 现在,发出GET请求:

r = urlopen("{0}?{1}".format(url, encodeddata))

To make a POST request: 发出POST请求:

r = urlopen(url, encodeddata)

Read the response: 阅读响应:

r.read()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM