Search code examples
pythonpython-2.7urllib2urllib

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.


Solution

  • This should work:

    payload = {
      'user': 'newuser',
      'pass': '12345',
      'tos_understood': 'on',
      }