欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Python3.2模拟实现webqq登录

程序员文章站 2022-05-27 13:13:35
...
这是我最初学习时自己做的一个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&style=5&mibao_css=m_webqq&appid=1003903&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fwebqq.qq.com%2Floginproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20110909003'\
  }
  __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)+'&appid=1003903&r='+ ('%s' % random.Random().random())
    str = self.__request(url = urlv, savecookie=True)
    str = re.findall(r'\d|(?

以上就是本文的全部内容,希望对大家学习python程序设计有所帮助。

Python3.2模拟实现webqq登录

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频