python代码添加微信号(python 获取微信好友列表的方法微信web)
类别:脚本大全 浏览量:1663
时间:2022-01-25 00:37:24 python代码添加微信号
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)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/Dopamy_BusyMonkey/article/details/74568558
您可能感兴趣
- python将对象转换成json(python对象与json相互转换的方法)
- python实现数据的预测(Python基于scipy实现信号滤波功能)
- python人脸识别实时教程(python dlib人脸识别代码实例)
- pythonmatplotlib怎么画区域(python matplotlib实现双Y轴的实例)
- python 摄像头运用(使用Python控制摄像头拍照并发邮件)
- pythonselenium自动化教程(python使用selenium实现批量文件下载)
- python编写计算机病毒教程(Python告诉你木马程序的键盘记录原理)
- python协程结果(深入浅析python 协程与go协程的区别)
- 如何用python爬取最新电影(详解Python爬取并下载《电影天堂》3千多部电影)
- pythonide使用教程(对Python Pexpect 模块的使用说明详解)
- python怎么转换jar包(利用python脚本如何简化jar操作命令)
- python用于机器人(python机器人运动范围问题的解答)
- python获取网络数据tcp(Python选择网卡发包及接收数据包)
- python 队列与列表(Python实现的栈、队列、文件目录遍历操作示例)
- python里面的time如何用(详解python:time模块用法)
- python去除字符串中间的空格(Python去除字符串前后空格的几种方法)
- 数字藏品市场有多乱 周杰伦丢了 一只猴 ,损失超300万(数字藏品市场有多乱)
- 这里输入关键词(怎么输入关键词搜索)
- 得这个 难治病 的人太多了,300个人赶到杭州商量怎么办(得这个难治病的人太多了)
- 经度,世界时间腕表的灵魂(世界时间腕表的灵魂)
- 阿里最新财报公布 三季度营收增长3 ,将增加150亿美元回购额度 在美股价小涨(阿里最新财报公布)
- 赵薇时胖时瘦 最近变美少女 原因在这里 躺着就变瘦(赵薇时胖时瘦最近变美)
热门推荐
- laravel自定义使用方法(laravel 获取当前url的别名方法)
- php技术优点和缺点(php的优点总结 php有哪些优点)
- python怎样读取mysql数据(使用Python将Mysql的查询数据导出到文件的方法)
- thinkphp5.0实例详解(ThinkPHP5&5.1框架关联模型分页操作示例)
- HTMl5 sessionStorage和localStorage
- python搭建django框架(详解Python网络框架Django和Scrapy安装指南)
- python自动处理图片(python制作图片缩略图)
- 移动端web页面使用position:fixed
- python爬虫面试经历(搞定这套Python爬虫面试题面试会so easy)
- 新买的云服务器注意事项(购买云服务器之前需要了解哪些知识?)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9