Putting a checkbox in python urllib

How can I check the box if the HTML 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 the tos_understood section? Unable to log in without checkbox.

+4
source share
2 answers

This should work:

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

You tried something like:

 "tos_understood": "1" "tos_understood": "checked" 

or

 "tos_understood": "on" 

I looked around to answer this, but could not find much.

If they don’t work, maybe try something like selenium, which actually controls the browser with the window, it is waaaayyy easier, and you can also run it headless so that the window does not pop up.

+2
source

Source: https://habr.com/ru/post/1481561/


All Articles