python3.2模拟实现webqq登录

这是我最初学习时自己做的一个python模拟登录webqq的实例代码,具体代码如下

import hashlib
from urllib import request,parse
from http import cookiejar
import re,random,time
import threading as th
import json.encoder as json_encode
import json.decoder as json_decode
class qq:
“””
login qq
“””
__headers ={
‘user-agent’:’mozilla/5.0 (windows nt 6.1; wow64) applewebkit/534.30 (khtml, like gecko) chrome/12.0.742.9 safari/534.30′,\
‘referer’:’http://ui.ptlogin2.qq.com/cgi-bin/login?target=self&\
}
__cookiepath = ‘c:\\users\\dingyangfan\\desktop\php\\tt.txt’
__qq = none
__pswd = none
__verifycode = none
__clientid = 21628014
__http = {}
__psessionid = ”
__ptwebqq = ”
__vfwebqq = ”
__skey = ”
__poll2 = none
__get_msg_tip = none
__rc = 0
__send_num = 31330000
def __init__(self):
self.httpproess()
self.__login()
pass
def __preprocess(self,password,verifycode):
“””
qq密码加密部份
“””
return hashlib.md5( (self.__md5_3((password).encode(‘utf-8’)) + (verifycode).upper()).encode(‘utf-8’)).hexdigest().upper()
pass
def __md5_3(self,str):
“””
qq密码md5_3部份
“””
return hashlib.md5(hashlib.md5(hashlib.md5(str).digest()).digest()).hexdigest().upper()
pass
def httpproess(self):
“””
初始化模拟进程
“””
self.__http[‘cj’] = cookiejar.mozillacookiejar(self.__cookiepath)
self.__http[‘opener’] = request.build_opener(request.httpcookieprocessor(self.__http[‘cj’]))
return self.__http
pass
def __request(self,url,method=’get’,data={},savecookie=false):
“””
请求url
“””
if (method).upper() == ‘post’:
data = parse.urlencode(data).encode(‘utf-8’)
self.__http[‘req’] = request.request(url,data,self.__headers)
else:
self.__http[‘req’] = request.request(url=url,headers=self.__headers)
fp = self.__http[‘opener’].open(self.__http[‘req’])
try:
str = fp.read().decode(‘utf-8’)
except unicodedecodeerror:
str = fp.read()
if savecookie == true:
self.__http[‘cj’].save(ignore_discard=true,ignore_expires=true)
fp.close()
return str
pass
def __getcookies(self,name):
fp = open(self.__cookiepath)
fp.seek(130)
for read in fp.readlines():
str = read.split(name)
if len(str) == 2:
fp.close()
return str[1].strip()
fp.close()
return none
pass
def __getverifycode(self):
“””
@url:http://ptlogin2.qq.com/check?uin=644826377&appid=1003903&r=0.56373973749578
“””
urlv = ‘http://ptlogin2.qq.com/check?uin=’+ (‘%s’ % self.__qq)+’&app+ (‘%s’ % random.random().random())
str = self.__request(url = urlv, savecookie=true)
str = re.findall(r’\d|(?

发表评论