python 翻译代码_将一段python代码大概翻译成java

这是一段模拟登陆论坛的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

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值