欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2019年02月21日 08:49:24   作者:BusyMonkey  
今天小編就為大家分享一篇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)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • pycharm利用pyspark遠(yuǎn)程連接spark集群的實現(xiàn)

    pycharm利用pyspark遠(yuǎn)程連接spark集群的實現(xiàn)

    由于工作需要,利用spark完成機(jī)器學(xué)習(xí)。因此需要對spark集群進(jìn)行操作。所以利用pycharm和pyspark遠(yuǎn)程連接spark集群。感興趣的可以了解一下
    2021-05-05
  • Python實現(xiàn)格式化輸出的實例詳解

    Python實現(xiàn)格式化輸出的實例詳解

    這篇文章主要為大家介紹了Python語法中實現(xiàn)格式化輸出的方法,本文通過幾個實例為大家進(jìn)行了詳細(xì)的講解,感興趣的小伙伴可以了解一下
    2022-08-08
  • 基于Python實現(xiàn)五子棋游戲

    基于Python實現(xiàn)五子棋游戲

    這篇文章主要為大家詳細(xì)介紹了基于Python實現(xiàn)五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • 使用Python生成url短鏈接的方法

    使用Python生成url短鏈接的方法

    這篇文章主要介紹了使用Python生成url短鏈接的方法,短鏈接在如今在微博等社交網(wǎng)站中等是非常常見的功能,需要的朋友可以參考下
    2015-05-05
  • 利用Python分析一下最近的股票市場

    利用Python分析一下最近的股票市場

    這篇文章主要為大家介紹了利用Python分析一下最近的股票市場的實現(xiàn)過程,數(shù)據(jù)獲取范圍為2022年一月一日到2022年2月25日,感興趣的可以了解一下
    2022-02-02
  • python3中sort和sorted使用與區(qū)別

    python3中sort和sorted使用與區(qū)別

    python3中sort()和sorted()都可以用來排序,本文主要介紹了python3中sort和sorted使用與區(qū)別,具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • 如何利用python將Xmind用例轉(zhuǎn)為Excel用例

    如何利用python將Xmind用例轉(zhuǎn)為Excel用例

    這篇文章主要介紹了如何利用python將Xmind用例轉(zhuǎn)為Excel用例,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-06-06
  • Python導(dǎo)入不同文件夾中文件的方法詳解

    Python導(dǎo)入不同文件夾中文件的方法詳解

    在寫python程序的時候,經(jīng)常會用到引入其他文件夾里的py文件,下面這篇文章主要給大家介紹了關(guān)于Python導(dǎo)入不同文件夾中文件的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • 使用python為mysql實現(xiàn)restful接口

    使用python為mysql實現(xiàn)restful接口

    這篇文章主要介紹了使用python為mysql實現(xiàn)restful接口的相關(guān)資料,需要的朋友可以參考下
    2018-01-01
  • python利用正則表達(dá)式排除集合中字符的功能示例

    python利用正則表達(dá)式排除集合中字符的功能示例

    在正則表達(dá)式里,想匹配一些字符中的一個,也就是說給出一個字符的集合,只要出現(xiàn)這個集合里任意的字符,都是成立的,下面這篇文章主要給大家介紹了關(guān)于python利用正則表達(dá)式排除集合中字符功能的相關(guān)資料,需要的朋友可以參考下。
    2017-10-10

最新評論