import urllib2, re, urllib
def login():
host = "http://localhost/cms/"
user = 'admin'
passw = 'admin'
error = "Login to CMS Made Simple"
form = [
('username', user),
('password', word)]
target = host + "/admin/login.php"
login_form_data = urllib.urlencode(form)
opener = urllib2.build_opener(target)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
source = opener.open(target, login_form_data).read()
if re.search(error, source) == None :
print 'FOund =>>>' + target + 'Username : ' + user + 'Password : ' + word
else:
print 'Not Found=>> ' + target + ' Username : ' + user + 'Password : ' + word
login()
我得到这个:
opener = urllib2.build_opener(host)
File "D:\Python27\lib\urllib2.py", line 486, in build_opener
opener.add_handler(h)
File "D:\Python27\lib\urllib2.py", line 322, in add_handler
type(handler))
TypeError: expected BaseHandler instance, got <type 'str'>
我认为问题出在这里:opener = urllib2.build_opener(target)
但是如何解决呢?我尝试了很多。