当前位置: 首页 > 编程笔记 >

python 获取微信好友列表的方法(微信web)

欧奇希
2023-03-14
本文向大家介绍python 获取微信好友列表的方法(微信web),包括了python 获取微信好友列表的方法(微信web)的使用技巧和注意事项,需要的朋友参考一下

如下所示:

 
import urllib
import urllib2 
import os
import time
import re 
import cookielib 
import xml.dom.minidom 
import json
 
tip = 0 
uuid = ''
successUrl = ''
skey = ''
wxsid = ''
wxuin = ''
pass_ticket = ''
deviceId = 'e000000000000000'
imagesPath = os.getcwd() + '/weixin.jpg'
 
BaseRequest = {}
base_uri = '' 
push_uri = ''
 
def getUUID():
  global uuid
  url = 'https://login.weixin.qq.com/jslogin'
  values = { 
    'appid':'wx782c26e4c19acffb',
    'redirect_uri':'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage',
    'fun':'new',
    'lang':'zh_CN',
    '_':int(time.time())
  } 
  request = urllib2.Request(url=url, data=urllib.urlencode(values))  
  response = urllib2.urlopen(request)
  data = response.read() 
  print data 
   
  regx = r'window.QRLogin.code = (\d+); window.QRLogin.uuid = "(\S+?)"' 
  pm = re.search(regx, data) 
  code = pm.group(1) 
  uuid = pm.group(2) 
  print code, uuid 
   
  if code == '200': 
    return True 
  return False 
 
def show2DimensionCode(): 
  global tip
 
  url = 'https://login.weixin.qq.com/qrcode/' + uuid 
  values = { 
    't':'webwx',
    '_':int(time.time()) 
  } 
 
  request = urllib2.Request(url=url, data=urllib.urlencode(values)) 
  response = urllib2.urlopen(request) 
  tip = 1 
 
  f = open(imagesPath, 'wb') 
  f.write(response.read()) 
  f.close() 
  time.sleep(1)
  os.system('call %s' % imagesPath) 
  print u'please sacn qcode by your phone'.encode('GBK') 
  
def isLoginSucess():
  global successUrl, base_uri, push_uri
  
  url = 'https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s' % (tip, uuid, int(time.time())) 
  request = urllib2.Request(url=url) 
  response = urllib2.urlopen(request) 
  data = response.read() 
  print data 
  regx = r'window.code=(\d+)'
  regxLogin = r'window.redirect_uri="(\S+?)"' 
  pm = re.search(regx, data) 
  pmLogin = re.search(regxLogin, data)
  code = pm.group(1)
  if pmLogin != None:
   successUrl = pmLogin.group(1) + '&fun=new&version=v2'
 
  if code == '201': 
    print'Scan QR code successfully!' 
  elif code == '200': 
    print'Logining...' 
    services = [ 
     ('wx2.qq.com', 'webpush2.weixin.qq.com'), 
     ('qq.com', 'webpush.weixin.qq.com'), 
     ('web1.wechat.com', 'webpush1.wechat.com'), 
     ('web2.wechat.com', 'webpush2.wechat.com'), 
     ('wechat.com', 'webpush.wechat.com'), 
     ('web1.wechatapp.com', 'webpush1.wechatapp.com'), 
    ] 
    base_uri = successUrl[:successUrl.rfind('/')] 
    push_uri = base_uri 
    for (searchUrl, pushUrl) in services: 
     if base_uri.find(searchUrl) >= 0: 
      push_uri = 'https://%s/cgi-bin/mmwebwx-bin' % pushUrl 
      break 
  elif code == '408': 
    print'Login Timeout!'
 
  return code  
 
def webwxnewloginpage():
 global successUrl, skey, wxsid, wxuin, pass_ticket, BaseRequest
 
 request = urllib2.Request(url=successUrl) 
 response = urllib2.urlopen(request) 
 data = response.read()
 
 doc = xml.dom.minidom.parseString(data) 
 root = doc.documentElement 
 
 for node in root.childNodes: 
  if node.nodeName == 'skey': 
   skey = node.childNodes[0].data 
  elif node.nodeName == 'wxsid': 
   wxsid = node.childNodes[0].data 
  elif node.nodeName == 'wxuin': 
   wxuin = node.childNodes[0].data 
  elif node.nodeName == 'pass_ticket': 
   pass_ticket = node.childNodes[0].data
   
 BaseRequest = { 
  'Uin': wxuin, 
  'Sid': wxsid, 
  'Skey': skey, 
  'DeviceID': deviceId, 
 }
 
def webwxinit(): 
 global skey, pass_ticket, BaseRequest, base_uri
 
 url = (base_uri + '/webwxinit?pass_ticket=%s&skey=%s&r=%s' % (pass_ticket, skey, int(time.time()))) 
 params = {'BaseRequest': BaseRequest} 
 headers = {'content-type': 'application/json; charset=UTF-8'}
 request = urllib2.Request(url=url, data=json.dumps(params), headers=headers) 
 response = urllib2.urlopen(request) 
 data = response.read()
 print data
 
def webwxgetcontact(): 
 global skey, pass_ticket, base_uri
  
 url = (base_uri + '/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s' % (pass_ticket, skey, int(time.time()))) 
 headers = {'content-type': 'application/json; charset=UTF-8'}
 request = urllib2.Request(url=url, headers=headers) 
 response = urllib2.urlopen(request)
 data = response.read()
 print data
 
def main(): 
 
  cookie = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) 
  urllib2.install_opener(cookie) 
 
  if getUUID() == False: 
   print'Get uuid unsuccessfully!' 
   return None 
 
  show2DimensionCode() 
  time.sleep(1) 
 
  while isLoginSucess() != '200': 
   pass 
 
  webwxnewloginpage()
#   time.sleep(1)
#   webwxinit()
  time.sleep(1)
  webwxgetcontact()
  
  os.remove(imagesPath) 
  print'Login successfully!' 
 
if __name__ == '__main__': 
  print'Welcome to use weixin personnal version' 
  print'Please click Enter key to continue......'
  main()
  

以上这篇python 获取微信好友列表的方法(微信web)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持小牛知识库。

 类似资料:
  • 本文向大家介绍java获取微信accessToken的方法,包括了java获取微信accessToken的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了java如何获取微信accessToken,供大家参考,具体内容如下 GET请求 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

  • 本文向大家介绍SpringBoot中获取微信用户信息的方法,包括了SpringBoot中获取微信用户信息的方法的使用技巧和注意事项,需要的朋友参考一下 前言 不知道你是否参加过拼多多上邀请微信好友砍价功能,这个功能实现首先需要考虑的就是获取微信用户的信息。获取用户信息就是获取公众号下微信用户的信息,今天我就来讲讲如何从公众号下获取微信用户信息。 需要声明一点的是获取微信公众号下的用户信息的权限是服

  • 本文向大家介绍python轻松查到删除自己的微信好友,包括了python轻松查到删除自己的微信好友的使用技巧和注意事项,需要的朋友参考一下 前言 相信各位一定有收到过这样的群发短信,据说还被归类为玩转微信的五大技巧之一╮(╯▽╰)╭但,其实,只要跑一下脚本,就轻松找出删除自己的好友(轻松摔碎玻璃心,逃 原理 新建群组,如果加不进来就是被删好友了(不要在群组里讲话,别人是看不见的)。 用的是微信网页

  • 本文向大家介绍python获取天气接口给指定微信好友发天气预报,包括了python获取天气接口给指定微信好友发天气预报的使用技巧和注意事项,需要的朋友参考一下 先看下效果图: 用到的模块: PyMySQL requests threading wxpy 要实现上面的示例,首先是有两大块地方 获取天气信息 通过微信将天气信息发送出去 而获取天气信息又包括几个小的需要注意的地方 获取天气信息 获取天气

  • 问题内容: 每次我尝试使用ffmpeg获取有关我的视频文件的信息时,都会吐出很多无用的信息,混杂着很多好东西。 我正在使用。 有没有可能以友好的方式实现这一目标?我的意思是JSON会很棒(甚至丑陋的XML也可以)。 至此,我使我的应用程序使用正则表达式解析数据,但是在某些特定的视频文件上却出现了很多讨厌的角落。我已修复所有遇到的问题,但可能还会更多。 我想要类似的东西: 问题答案: 有点晚了,但也

  • 本文向大家介绍Python微信操控itchat的方法,包括了Python微信操控itchat的方法的使用技巧和注意事项,需要的朋友参考一下 itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单。 开源地址 https://github.com/littlecodersh/ItChat 文档: https://itchat.readthedocs.io/zh/latest/

  • 本文向大家介绍python给微信好友定时推送消息的示例,包括了python给微信好友定时推送消息的示例的使用技巧和注意事项,需要的朋友参考一下 如下所示: 以上这篇python给微信好友定时推送消息的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持呐喊教程。

  • 本文向大家介绍使用python itchat包爬取微信好友头像形成矩形头像集的方法,包括了使用python itchat包爬取微信好友头像形成矩形头像集的方法的使用技巧和注意事项,需要的朋友参考一下 初学python,我们必须干点有意思的事!从微信下手吧! 头像集样例如下: 大家可以发朋友圈开启辨认大赛哈哈~ 话不多说,直接上代码,注释我写了比较多,大家应该能看懂 运行结果: ok!!! 以上这篇