这是一段模拟登陆论坛的python代码代码如下classloginInfo(QtCore.QThread):def__init__(self,conn,parent):QtCore.QThread.__init__(self,parent)self.conn=connself.username,self....
这是一段模拟登陆论坛的python代码
代码如下
class loginInfo(QtCore.QThread):
def __init__(self, conn, parent):
QtCore.QThread.__init__(self, parent)
self.conn = conn
self.username, self.password = self.conn.getUsernameAndPassword()
def run(self):
mutex2.lock()
self.status = self.getConnection()
mutex2.unlock()
def getConnection(self):
md5passwd = hashlib.md5(self.password).hexdigest()
self.passwd = md5passwd[8:24]
self.conn.setPasswd(self.passwd)
self.conn = httplib.HTTPConnection("www.cc98.org")
self.conn.putrequest("GET", "/index.asp")
self.conn.endheaders()
res = self.conn.getresponse()
res.read()
self.cookie = res.getheader("set-cookie")
sessionlist = re.findall(r"ASPSESSION.*(?=; path=/)", self.cookie)
session = sessionlist[0]
self.cookie = "BoardList=BoardID=Show; " + session
data = urllib.urlencode({"a":"i", "u":self.username, "p":md5passwd, "userhidden":"2"})
Content_Length = data.__len__()
self.conn.putrequest("GET", "/sign.asp")
self.conn.putheader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
self.conn.putheader("Cookie", self.cookie)
self.conn.putheader("Content-Length", str(Content_Length))
self.conn.endheaders()
self.conn.send(data)
res = self.conn.getresponse()
if res.read() != "9898":
return False
userinfo = re.findall(r"aspsky.*?(?=;\s)", res.getheader("set-cookie"))
self.cookie = "BoardList=BoardID=Show; upNum=0; " + session + "; " + userinfo[0]
return True
def getStatus(self):
return self.status
def getCookie(self):
return self.cookie
展开