The examples in this article share the specific code deleted by a python friend for your reference. the specific content is as follows # weixin. py # coding: UTF-8 #! Usrbinenvpython # codingutf-8 # through this program can be found to be deleted friends importosimporturllib, examples. dom. minido this article examples for everyone to share the python friends to delete the specific code for your reference, the specific content is as follows
# Weixin. py # coding: UTF-8 #! /Usr/bin/env python # coding = UTF-8 # using this program, you can find the deleted friends import osimport urllib and urllib2import reimport cookielibimport timeimport xml. dom. minidomimport jsonimport sysimport mathDEBUG = FalseMAX_GROUP_NUM = 35 # QRImagePath = OS. getcwd () + '/qrcode.jpg' tip = 0 uuid = ''base _ uri ='' redirect _ uri = ''skey ='' wxsid = ''wxuin ='' pass _ ticket = ''deviceid = 'e00000000000' BaseRequest = {} ContactList = [] My = [] def getUUID (): global uuid url =' https://login.weixin.qq.com/jslogin 'Params = {'appid ': 'wx782c26e4c19acffb', 'Fun': 'New', 'Lang ': 'zh _ cn',' _ ': int (time. time (),} request = urllib2.Request (url = url, data = urllib. urlencode (params) response = urllib2.urlopen (request) data = response. read () # print data # window. QRLogin. code = 200; window. QRLogin. uuid = "oZwt_bFfRg ="; regx = r'window. QRLogin. code = (\ d +); window. QRLogin. uuid = "(\ S + ?) "'PM = re. search (regx, data) code = pm. group (1) uuid = pm. group (2) if code = '000000': return True return Falsedef showQRImage (): global tip url =' https://login.weixin.qq.com/qrcode/ '+ Uuid params = {'T': 'webwx', '_': int (time. time (),} request = urllib2.Request (url = url, data = urllib. urlencode (params) response = urllib2.urlopen (request) tip = 1 f = open (QRImagePath, 'wb') f. write (response. read () f. close () if sys. platform. find ('Darwin')> = 0: OS. system ('open % s' % QRImagePath) elif sys. platform. find ('Linux ')> = 0: OS. system ('xdg-open % s' % QRImagePath) else: OS. system ('Call % s' % QRImagePath) print 'use the scan QR code to log on to 'Def waitForLogin (): global tip, base_uri, redirect_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 # window. code = 500; regx = r'window. code = (\ d +); 'pm = re. search (regx, data) code = pm. group (1) if code = '000000': # print scanned successfully. click Confirm on your phone to log on to 'tip = 0 elif code = '000000 ': # logged on print 'logging on... 'regx = R' window. redirect_uri = "(\ S + ?) "; 'PM = re. search (regx, data) redirect_uri = pm. group (1) + '& fun = new' base_uri = redirect_uri [: redirect_uri.rfind ('/')] elif code = '000000 ': # timeout pass # elif code = '000000' or code = '000000': return codedef login (): global skey, wxsid, wxuin, pass_ticket, baseRequest request = urllib2.Request (url = redirect_uri) response = urllib2.urlopen (request) data = response. read () # print data '''
0
OK
Xxx
Xxx
Xxx
Xxx
1
'''Doc = xml. dom. minidom. parseString (data) root = doc.doc umentElement 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 # print 'skey: % s, wxsid: % s, wxuin: % s, Pass_ticket: % s' % (skey, wxsid, wxuin, pass_ticket) if skey = ''or wxsid ='' or wxuin = ''or pass_ticket = '': return False BaseRequest = {'uin': int (wxuin), 'Sid': wxsid, 'skey ': Skey, 'deviceid': DeviceID,} return Truedef webwxinit (): url = base_uri + '/webwxinit? Pass_ticket = % s & skey = % s & r = % s' % (pass_ticket, skey, int (time. time () params = {'baserequest ': BaseRequest} request = urllib2.Request (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = urllib2.urlopen (request) data = response. read () if DEBUG = True: f = open (OS. getcwd () + '/webwxinit. json', 'WB ') f. write (data) f. close () # print data g Lobal ContactList, My dic = json. loads (data) ContactList = dic ['contactlist'] My = dic ['user'] ErrMsg = dic ['baseresponse'] ['errmsg '] if len (ErrMsg)> 0: print ErrMsg Ret = dic ['baseresponse'] ['ret '] if Ret! = 0: return False return Truedef webwxgetcontact (): url = base_uri + '/webwxgetcontact? Pass_ticket = % s & skey = % s & r = % s' % (pass_ticket, skey, int (time. time () request = urllib2.Request (url = url) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = urllib2.urlopen (request) data = response. read () if DEBUG = True: f = open (OS. getcwd () + '/webwxgetcontact. json', 'WB ') f. write (data) f. close () # print data dic = json. loads (data) MemberList = dic ['memberlist'] # reverse traversal Otherwise, a problem occurs during deletion .. specialUsers = ['newsapp', 'fmessage', 'filehelper ', 'Weibo', 'qqmail ', 'fmessage', 'tmessage', 'qmessage', 'qqsync ', 'floatbottle', 'lbsapp', 'shakeapp', 'medianote', 'qqfriend', 'readerapp', 'blogapp', 'facebookapp', 'masssendapp', 'meishiapp ', 'feedsapp', 'voip ', 'blogappweixin', 'weixin', 'brandsessionholder', 'weixinreminder', 'wxid _ upload', 'GH _ 22b87fa7cb3c', 'officiala Ccounts ', 'notification _ messages', 'wxid _ novlwrv3lqwv11', 'GH _ 22b87fa7cb3c ', 'wxitil', 'userexperience _ alarm ', 'notification _ messages '] for I in xrange (len (MemberList)-1,-1,-1 ): member = MemberList [I] if Member ['verifyflag'] & 8! = 0: # public account/service number MemberList. remove (Member) elif Member ['username'] in SpecialUsers: # special account MemberList. remove (Member) elif Member ['username']. find ('@@')! =-1: # group chat MemberList. remove (Member) elif Member ['username'] = My ['username']: # Your own MemberList. remove (Member) return MemberListdef createChatroom (UserNames): MemberList = [] for UserName in UserNames: MemberList. append ({'username': UserName}) url = base_uri + '/webwxcreatechatroom? Pass_ticket = % s & r = % s' % (pass_ticket, int (time. time () params = {'baserequest ': BaseRequest, 'membercount': len (MemberList), 'memberlist': MemberList, 'topic ':'',} request = urllib2.Request (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = urllib2.urlopen (request) data = response. read () # print data dic = json. loads (data) ChatRoomNa Me = dic ['chatroomname'] MemberList = dic ['memberlist'] DeletedList = [] for Member in MemberList: if Member ['memberstatus'] = 4: # DeletedList is deleted by the other party. append (Member ['username']) ErrMsg = dic ['baseresponse'] ['errmsg '] if len (ErrMsg)> 0: print ErrMsg return (ChatRoomName, DeletedList) def deleteMember (ChatRoomName, UserNames): url = base_uri + '/webwxupdatechatroom? Fun = delmember & pass_ticket = % s' % (pass_ticket) params = {'baserequest ': BaseRequest, 'chatroomname': ChatRoomName, 'delmemberlist ':','. join (UserNames),} request = urllib2.Request (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = urllib2.urlopen (request) data = response. read () # print data dic = json. loads (data) ErrMsg = dic ['baseresp Onse '] ['errmsg'] if len (ErrMsg)> 0: print ErrMsg Ret = dic ['baseresponse'] ['ret '] if Ret! = 0: return False return Truedef addMember (ChatRoomName, UserNames): url = base_uri + '/webwxupdatechatroom? Fun = addmember & pass_ticket = % s' % (pass_ticket) params = {'baserequest ': BaseRequest, 'chatroomname': ChatRoomName, 'addmemberlist ':','. join (UserNames),} request = urllib2.Request (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = urllib2.urlopen (request) data = response. read () # print data dic = json. loads (data) MemberList = dic ['memb Erlist'] DeletedList = [] for Member in MemberList: if Member ['memberstatus'] = 4: # DeletedList is deleted by the other party. append (Member ['username']) ErrMsg = dic ['baseresponse'] ['errmsg '] if len (ErrMsg)> 0: print ErrMsg return DeletedListdef main (): opener = urllib2.build _ opener (urllib2.HTTPCookieProcessor (cookielib. cookieJar () urllib2.install _ opener (opener) if getUUID () = False: print 'failed to get uuid 'return showQR Image () time. sleep (1) while waitForLogin ()! = '000000': pass OS. remove (QRImagePath) if login () = False: print 'logon failed' return if webwxinit () = False: print 'initialization failed' return MemberList = webwxgetcontact () memberCount = len (MemberList) print 'contacts % s Friends '% MemberCount ChatRoomName = ''result = [] for I in xrange (0, int (math. ceil (MemberCount/float (MAX_GROUP_NUM): UserNames = [] NickNames = [] DeletedList = ''for j in xrange (0, MAX_GROUP_NUM ): If I * MAX_GROUP_NUM + j> = MemberCount: break Member = MemberList [I * MAX_GROUP_NUM + j] UserNames. append (Member ['username']) NickNames. append (Member ['nickname']. encode ('utf-8') print 'group % s... '% (I + 1) print ','. join (NickNames) print 'Enter key to continue... 'raw_input () # create a group/add a member if ChatRoomName = '': (ChatRoomName, DeletedList) = createChatroom (UserNames) else: DeletedList = addMember (ChatRoomName, Use RNames) DeletedCount = len (DeletedList) if DeletedCount> 0: result + = DeletedList print '% s deleted friends' % DeletedCount # raw_input () # delete member deleteMember (ChatRoomName, userNames) # todo delete group resultNames = [] for Member in MemberList: if Member ['username'] in result: nickName = Member ['nickname'] if Member ['remarkname']! = '': NickName + = '(% s)' % Member ['remarkname'] resultNames. append (NickName. encode ('utf-8') print '---------- deleted friend list ---------- 'print' \ n '. join (resultNames) print '-----------------------------------' # fixed the encoding problem in windows. class UnicodeStreamFilter: def _ init _ (self, target): self.tar get = target self. encoding = 'utf-8' self. errors = 'replace 'self. encode_to = self.tar get. encoding def write (self, s): if type (s) = str: s = s. decode ('utf-8') s = s. encode (self. encode_to, self. errors ). decode (self. encode_to) self.tar get. write (s) if sys. stdout. encoding = 'cp936': sys. stdout = UnicodeStreamFilter (sys. stdout) if _ name _ = '_ main _': print 'The query result of this program may cause some psychological discomfort. please be careful when using it... 'print 'Enter key to continue... 'raw_input () main () print' enter key to end 'raw_input ()
The preceding figure shows how to check whether a friend deletes his/her details in python. For more information, see other related articles in the first PHP community!