Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox input in python urllib

How can I check checkbox if HTML code looks like:

<input type="checkbox" name="tos_understood" style="background:none; border:none" />

So, my python code is:

import urllib
import urllib2
import cookielib

authentication_url = 'http://test.com'

# Input parameters we are going to send
payload = {
  'user': 'newuser',
  'pass': '12345'
  'tos_understood': ??????????
  }

# Use urllib to encode the payload
data = urllib.urlencode(payload)

# Build our Request object
req = urllib2.Request(authentication_url, data)
print req

# Make the request and read the response
resp = urllib2.urlopen(req)
contents = resp.read()
print contents

What should I write in tos_understood section? There is no way to login without checked checkbox.

like image 758
Alex Smith Avatar asked Oct 04 '22 02:10

Alex Smith


2 Answers

This should work:

payload = {
  'user': 'newuser',
  'pass': '12345',
  'tos_understood': 'on',
  }
like image 69
stalk Avatar answered Oct 13 '22 11:10

stalk


did you try something like :

"tos_understood": "1"

 "tos_understood": "checked"

or

"tos_understood": "on"

I looked around for an answer to this but couldnt really find much

If those dont work maybe try something like selenium that actually drives a browser with a window it is waaaayyy easier and you can also run it headless so that the window doesn't pop up

like image 26
Serial Avatar answered Oct 13 '22 12:10

Serial