python 获取微信好友列表的方法(微信web)
作者:BusyMonkey 发布时间:2022-02-20 10:05:21
标签:python,微信,好友,列表
如下所示:
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()
来源:https://blog.csdn.net/Dopamy_BusyMonkey/article/details/74568558
0
投稿
猜你喜欢
- 汉字转为拼音的asp函数,原理:利用多维数组 1.添加索引 2.遍历数组Author: Unknowasp之家测试截图,呵呵不错:<%
- 在我们常用的系统windows和Linux系统中有很多支持的压缩包格式,包括但不限于以下种类:rar、zip、tar,以下的标准库的作用就是
- 本游戏程序实现的功能为本地二人对弈中国象棋,实现语言为javascript+VML,在windows 2000 pro+IE 6sp1的环境
- Tkinter 是 Python 的标准 GUI 库。Python 使用 Tkinter 可以快速的创建 GUI 应用程序。这篇文章使用tk
- CSV(Comma-Separated Values)即逗号分隔值,一种以逗号分隔按行存储的文本文件,所有的值都表现为字符串类型(注意:数字
- 本文实例为大家分享了Python实现发送QQ邮件的封装代码,供大家参考,具体内容如下封装codeimport smtplibfrom ema
- 最近在看吴恩达的机器学习课程,自己用python实现了其中的logistic算法,并用梯度下降获取最优值。logistic分类是一个二分类问
- 在XHTML标签中有一些标签的作用是相似的,当然这里的相似是指语义相似,以至于很多人都不清楚这些相似的标签如何使用,那么今天的主题就是分解相
- 这篇文章主要介绍了Oracle数据库到SQL Server数据库主键的迁移过程,具体内容请参考下文。由于项目需要要将以前Oracle的数据库
- 我们经常使用傅里叶变换来计算数字信号的频谱,进而分析数字信号,离散时间傅里叶变换的公式为:可是自己动手实现一遍才是最好的学习。在数字分析里面
- 前言日常生活中,手残党们经常会把一些照片拍歪,比如拍个证件、试卷、PPT什么的,比如下面这本书的封面原本是个矩形,随手一拍就成了不规则四边形
- 如下所示:#统计某文件夹下的所有csv文件的行数(多线程)import threadingimport csvimport osclass
- 调用函数:#!/usr/bin/env python3 # -*- coding: utf-8 -*- # 函数调用 >>>
- 本文实例讲述了Python实现的基数排序算法。分享给大家供大家参考,具体如下:基数排序(radix sort)属于“分配式排序”(distr
- 把昨天做的高级查询界面完善了一下,支持动态添加多个查询条件、定义逻辑关系,支持整形、浮点、字符串、日期、布尔值、自定义选择列表的录入,通过E
- 这篇文章主要介绍了Python中使用gflags实例及原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
- 开发环境:python 3.6django 1.11场景一经常有从数据库中获取一批数据,然后在前端以列表的形式展现,比如:获取到所有的用户,
- 使用字符串时,常见的操作之一是使用给定的分隔符将字符串拆分为子字符串数组。在本文中,我们将讨论如何在Python中拆分字符串。.split(
- Matplotlib简介Matplotlib是非常强大的python画图工具Matplotlib可以画图线图、散点图、等高线图、条形图、柱形
- 前言 大家好,好男人就是我,我就是好男人,我就是-0nise。在各大漏洞举报平台,我们时常会