这是我最初学习时自己做的一个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""" 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""" urlv = 'http://ptlogin2.qq.com/check""" @url:http://ptlogin2.qq.com/login @params:{u:644826377 p:73DA5C1145E0F82247F60B3A17B89E6A verifycode:!S10 webqq_type:10 remember_uin:1 login2qq:1 aid:1003903 u1:http://webqq.qq.com/loginproxy.html""" urlv = 'http://ptlogin2.qq.com/login"&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Fstrong%3Dtrue" + '&h=1&ptredirect=0&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert' str = self.__request(url = urlv,savecookie=True) if str.find('登录成功') != -1: #执行二次登录 self.__ptwebqq = self.__getcookies('ptwebqq') self.__skey = self.__getcookies('skey') self.__request_post() elif str.find('不正确') != -1: print('你输入的帐号或者密码不正确,请重新输入。') else: print('登录失败') pass def __request_post(self): ''' http://d.web2.qq.com/channel/login2 r:{"status":"online","ptwebqq":"95b148b95af9be7677757b3a629e3904f52f153d0b714c527f81f8d9e385867a","passwd_sig":"", "clientid":"21628014","psessionid":null} clientid:21628014 psessionid:null ''' self.__headers.update({'Referer':'http://d.web2.qq.com/proxy.html""" 不知道干嘛的,一分钟连接一次,属于长连接,接收消息 @url:http://d.web2.qq.com/channel/poll2 r:{"clientid":"9467930","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3132382e36362e31313500003058000000c0026e040009456f266d0000000a407169446b464737436b6d00000028f8d256743e5c191cb40a2217845fab12fda62acd2e6145ae196976d7a8b3bb11a64d3c9565868322","key":0,"ids":[]} clientid:9467930 psessionid:8368046764001e636f6e6e7365727665725f77656271714031302e3132382e36362e31313500003058000000c0026e040009456f266d0000000a407169446b464737436b6d00000028f8d256743e5c191cb40a2217845fab12fda62acd2e6145ae196976d7a8b3bb11a64d3c9565868322 """ self.__headers.update({'Referer':'http://d.web2.qq.com/proxy.html""" #也不知道是什么,反正一直请求 @url:http://webqq.qq.com/web2/get_msg_tip""" self.__headers.update({'Referer':'http://webqq.qq.com/'}) self.__rc += 1 num = 100 + self.__rc t = '%s' % '%d' % time.time() + '%s' % num urlv = 'http://webqq.qq.com/web2/get_msg_tip"to":3023379661,"face":180,"content":"[\"哈哈\",\"\\n【提示:此用户正在使用WebQQ:http://webqq.qq.com/】\",[\"font\", {\"name\":\"宋体\",\"size\":\"10\",\"style\":[0,0,0],\"color\":\"000000\"}]]","msg_id":31330001,"clientid":"76133590", "psessionid":"s"} clientid:76133590 psessionid:s Referer:http://d.web2.qq.com/proxy.html"retcode":0,"result":"ok"} ''' self.__send_num +=1 msg = "[\""+ msg +"\",[\"font\",{\"name\":\"宋体\",\"size\":\"10\",\"style\":[0,0,0],\"color\":\"000000\"}]]" self.__headers.update({'Referer':'http://d.web2.qq.com/proxy.html"retcode":0,"result":[{"poll_type":"message","value":{"msg_id":13013,"from_uin":3023379661,"to_uin":644826377,"msg_id2":503935,"msg_type":9,"reply_ip":176752345,"time":1316143960,"content":[["font",{"size":13,"color":"000000","style":[0,0,0],"name":"\u5B8B\u4F53"}],"\u4E0D\u662F\u5427\u3002"]}}]} ''' self.__send_message(uid,'我是机器人%s' % time.time()) pass def __send_group_message(self,gid,msg): ''' @url:http://d.web2.qq.com/channel/send_qun_msg2 r:{"group_uin":1132101900,"content":"[\"哈哈哈,测试\",\"\\n【提示:此用户正在使用WebQQ:http://webqq.qq.com/】\",[\"font\", {\"name\":\"宋体\",\"size\":\"10\",\"style\":[0,0,0],\"color\":\"000000\"}]]","msg_id":31330002,"clientid":"76133590", "psessionid":"a"} clientid:76133590 psessionid:a Referer:http://d.web2.qq.com/proxy.html"retcode":0,"result":"ok"} ''' self.__send_num +=1 msg = "[\"" +msg + "\",[\"font\",{\"name\":\"宋体\",\"size\":\"10\",\"style\":[0,0,0],\"color\":\"000000\"}]]" self.__headers.update({'Referer':'http://d.web2.qq.com/proxy.html"retcode":0,"result":[{"poll_type":"group_message","value":{"msg_id":8044,"from_uin":1132101900,"to_uin":644826377,"msg_id2":178306,"msg_type":43,"reply_ip":2886742214,"group_code":317106137,"send_uin":3023379661,"seq":10654,"time":1316143836,"info_seq":32946855,"content":[["font",{"size":13,"color":"000000","style":[0,0,0],"name":"\u5B8B\u4F53"}],"\u5DE5"]}}]} ''' self.__send_group_message(gid,'我是机器人%s' % time.time()) pass def __Login(self): """ qq登录 """ self.__qq = input('QQ号:') self.__pswd = input('QQ密码:') self.__qq = self.__qq.strip() self.__pswd = self.__pswd.strip() self.__verifycode = self.__getverifycode() self.__pswd = self.__preprocess( self.__pswd,#密码 '%s' % self.__verifycode[1] #验证码 ) self.__request_login() pass s = QQ()
以上就是本文的全部内容,希望对大家学习python程序设计有所帮助。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]