python urllib中的复选框输入

Ale*_*ith 5 python urllib urllib2 python-2.7

如果 HTML 代码如下所示,如何检查复选框:

<input type="checkbox" name="tos_understood" style="background:none; border:none" />
Run Code Online (Sandbox Code Playgroud)

所以,我的python代码是:

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
Run Code Online (Sandbox Code Playgroud)

我应该在 tos_understood 部分写什么?没有选中复选框就无法登录。

sta*_*alk 2

这应该有效:

payload = {
  'user': 'newuser',
  'pass': '12345',
  'tos_understood': 'on',
  }
Run Code Online (Sandbox Code Playgroud)