我阅读此页面并且代码仍无效: Logging in to vBulletin
我的代码:
#-*- coding:utf-8 -*-
import urllib, urllib2, cookielib, hashlib, time
def variables():
domain = "www.example.com"
uname = "UserName"
passwd = "Password"
# Create url
if domain.startswith('http://'):
url = domain
else:
url = 'http://' + domain
login(url, uname, passwd)
def login(url, uname, passwd):
loginurl = url + '/login.php?do=login'
md5 = hashlib.md5(passwd);md5 = md5.hexdigest()
# Options for request
opts = {
'do': 'login',
'vb_login_md5password': md5,
'vb_login_md5password_utf': md5,
's': '',
'vb_login_username': uname,
'security_token': 'guest',
}
data = urllib.urlencode(opts)
# Request header
global headers
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'es-es,es;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip,deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection': 'keep-alive',
'Referer': loginurl,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Lenght': '205'
}
# Cookie Handling
jar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
# Send Request
opener.addheader = headers
opener.open(loginurl, data)
# Check
response = opener.open('http://example.com/')
source_code = response.read()
if source_code.find(uname) != -1:
print "Login Succeeded."
else:
print "Login Failed."
variables()
字段名称的属性值为None(Empty):
<input type="hidden" name="s" value="" />
为什么代码不起作用?
感谢。
答案 0 :(得分:0)
缺少“vb_login_password”,“vb_login_password_hint”,“cookieuser”和“vb_login_md5password_utf”必须为空。
并确定删除标题。