1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
url = "url.php"
login = "moi"
password = "XXX"
import ClientForm
import urllib2
request = urllib2.Request(url)
response = urllib2.urlopen(request)
forms = ClientForm.ParseResponse(response, backwards_compat=False)
form = forms[0]
print "form:", form
control = form.find_control("action", type="hidden")
print "control.name, control.value, control.type:", control.name, control.value, control.type
control.readonly = False
control.value = login
control.readonly = True
print "control.name, control.value, control.type:", control.name, control.value, control.type
control = form.find_control("password", type="password")
print "control.name, control.value, control.type:", control.name, control.value, control.type
control.value = password
print "control.name, control.value, control.type:", control.name, control.value, control.type
request2 = form.click() # urllib2.Request object
try:
response2 = urllib2.urlopen(request2)
except urllib2.HTTPError, response2:
print "error here" |
Partager