I'm very new to python and I'm trying to 'select' a radio button that is within a survey on a website. I really have no idea where to start with the python code. I believe the survey is in javascript and when the submit button is clicked, it sends the data to the server running the survey. 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.
-
Use firebug, submit the form as usual; then inspect the post request to see what data is being sent. Then have a look at urlopenmshsayem– mshsayem2013年10月20日 05:40:33 +00:00Commented Oct 20, 2013 at 5:40
-
@yuvi I have no idea how to start the code, like an outline of what needs to be done. for example 1) do this 2) then this 3)etc. If you could help me out with this(not actual python code) or give me somme links to where i can find this out myself, that would be very helpful.loganrussell48– loganrussell482013年10月21日 19:23:37 +00:00Commented Oct 21, 2013 at 19:23
-
@mshsayem I have used firebug and submitted the form as usual and used the network tab to inspect the request, which is actually a get request. I just don't know what to do now. I see the parameters in the corresponding tab, and also the headers. I have never learned how to do http requests in python, and I have minimal knowledge about http requests in general. Any help you could give me would be so helpful. I have the requests library imported, as it it said to be better than other methods. import requests r=requests.get('surveygizmo.com') now I just need more help with paramsloganrussell48– loganrussell482013年10月23日 04:56:36 +00:00Commented Oct 23, 2013 at 4:56
1 Answer 1
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:
r = urlopen("{0}?{1}".format(url, encodeddata))
To make a POST request:
r = urlopen(url, encodeddata)
Read the response:
r.read()