Checkbox input in python urllib

2019-06-25 10:37发布

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.

2条回答
干净又极端
2楼-- · 2019-06-25 10:56

This should work:

payload = {
  'user': 'newuser',
  'pass': '12345',
  'tos_understood': 'on',
  }
查看更多
三岁会撩人
3楼-- · 2019-06-25 11:00

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

查看更多
登录 后发表回答