Use the WeChat search function based on Python to check who deleted you

Source: Internet
Author: User
This article mainly introduces how to implement search based on Python to view information about who deleted you. For more information, see the following scenario: Find who deleted me, directly copy the code and save it to a python file who. py, run this file in the python Environment

The Code is as follows. copy is saved to the who. py file and runs directly in the python environment:

#! /Usr/bin/env python # coding = utf-8from _ future _ import print_functionimport ostry: from urllib import urlencode, quote_plusexcept ImportError: from urllib. parse import urlencode, quote_plustry: import urllib2 as wdf_urllibfrom cookielib import CookieJarexcept ImportError: import urllib. request as wdf_urllibfrom http. cookiejar import CookieJarimport reimport timeimport xml. dom. minidomimport jsonimport Sysimport mathimport subprocessimport sslimport threadDEBUG = FalseMAX_GROUP_NUM = 35 # Number of people in each group INTERFACE_CALLING_INTERVAL = 20 # interface call interval, which is too short and prone to "too frequent operations ", MAX_PROGRESS_LEN = 50 QRImagePath = OS. path. join (OS. getcwd (), 'qrcode.jpg ') tip = 0 uuid = ''base _ uri ='' redirect _ uri = ''push _ uri ='' skey = ''wxsid ='' wxuin = ''pass _ ticket = ''deviceid = 'e000000000000000' BaseRequest ={} ContactList = [] My = [] SyncKey = [] try: xrangerange = xrange0000t: # python 3 passdef responseState (func, BaseResponse ): errMsg = BaseResponse ['errmsg '] Ret = BaseResponse ['ret'] if DEBUG or Ret! = 0: print ('func: % s, Ret: % d, ErrMsg: % s' % (func, Ret, ErrMsg) if Ret! = 0: return Falsereturn Truedef getRequest (url, data = None): try: data = data. encode ('utf-8') failed T: passfinally: return wdf_urllib.Request (url = url, data = data) def getUUID (): global uidurl =' https://login.weixin.qq.com/jslogin 'Params = {'appid ': 'wx782c26e4c19acffb', 'fun': 'new', 'lang ': 'zh _ cn',' _ ': int (time. time (),} request = getRequest (url = url, data = urlencode (params) response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace ') # 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 Truereturn Falsedef showQRImage (): global tipurl =' https://login.weixin.qq.com/qrcode/ '+ Uidparams = {'T': 'webwx', '_': int (time. time (),} request = getRequest (url = url, data = urlencode (params) response = wdf_urllib.urlopen (request) tip = 1f = open (QRImagePath, 'wb ') f. write (response. read () f. close () if sys. platform. find ('darwin')> = 0: subprocess. call (['open', QRImagePath]) elif sys. platform. find ('linux ')> = 0: subprocess. call (['xdg-open', QRImagePath]) else: OS. startfile (QRImagePath) print ('use scan QR code to log on to ') def waitForLogin (): global tip, base_uri, redirect_uri, push_uriurl =' https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s '% (Tip, uuid, int (time. time () request = getRequest (url = url) response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace ') # print (data) # window. code = 500; regx = r'window. code = (\ d +); 'pm = re. search (regx, data) code = pm. group (1) if code = '000000': # scanned print ('Scan successful, please click confirm on your cell phone to log on ') tip = 0 elif code = '000000': # print logged on ('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 ('/')] # ing between push_uri and base_uri) (That's amazing ..) 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'),] push_uri = base_urifor (searchUrl, pushUrl) in services: if your (searchUrl)> = 0: push_uri =' https://%s/cgi-bin/mmwebwx-bin '% PushUrlbreak # closeQRImageif sys. platform. find ('darwin')> = 0: # for OSX with Previewos. system ("osascript-e 'Quit app \" Preview \ "'") elif code = '000000 ': # timeout pass # elif code = '000000' or code = '000000': return codedef login (): global skey, wxsid, wxuin, pass_ticket, baseRequestrequest = getRequest (url = redirect_uri) response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace') # Print (data) doc = xml. dom. minidom. parseString (data) root = doc.doc umentElementfor node in root. childNodes: if node. nodeName = 'skey': skey = node. childNodes [0]. dataelif node. nodeName = 'wxsid ': wxsid = node. childNodes [0]. dataelif node. nodeName = 'wxuin': wxuin = node. childNodes [0]. dataelif 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 not all (skey, wxsid, wxuin, pass_ticket): return FalseBaseRequest = {'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 = getRequest (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = wdf_urllib.urlopen (request) data = response. read () if DEBUG: f = open (OS. path. join (OS. getcwd (), 'webwxinit. json '), 'wb') f. write (data) f. close () data = data. decode ('utf- 8 ', 'replace') # print (data) global ContactList, My, SyncKeydic = json. loads (data) ContactList = dic ['contactlist'] My = dic ['user'] SyncKey = dic ['synckey '] state = responseState ('webwxinit ', dic ['baseresponse']) return statedef webwxgetcontact (): url = base_uri + \ '/webwxgetcontact? Pass_ticket = % s & skey = % s & r = % s' % (pass_ticket, skey, int (time. time () request = getRequest (url = url) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = wdf_urllib.urlopen (request) data = response. read () if DEBUG: f = open (OS. path. join (OS. getcwd (), 'webwxgetcontact. json '), 'wb') f. write (data) f. close () # print (data) data = data. decode ('utf-8', 'replace ') dic = json. loads (data) MemberL Ist = dic ['memberlist'] # reverse traversal. Otherwise, a problem occurs during deletion .. specialUsers = ["newsapp", "fmessage", "filehelper", "weibo", "qqmail", "tmessage", "qmessage", "qqsync", "floatbottle ", "lbsapp", "shakeapp", "medianote", "qqfriend", "readerapp", "blogapp", "facebookapp", "masssendapp", "meishiapp", "feedsapp ", "voip", "blogappweixin", "weixin", "brandsessionholder", "weixinreminder", "wxid_novlwrv3lqwv11", "gh_22b87fa7cb 3c "," officialaccounts "," icationication_messages "," wxitil "," userexperience_alarm "] for I in range (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 = [{'username': UserName} for UserName in UserNames] url = base_uri + \ '/webwxcreatechatroom? Pass_ticket = % s & r = % s' % (pass_ticket, int (time. time () params = {'baserequest ': BaseRequest, 'membercount': len (MemberList), 'memberlist': MemberList, 'topic ':'',} request = getRequest (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace ') # print (data) dic = json. loads (da Ta) ChatRoomName = dic ['chatroomname'] MemberList = dic ['memberlist'] DeletedList = [] BlockedList = [] for Member in MemberList: if Member ['memberstatus'] = 4: # The edlist is deleted by the other party. append (Member ['username']) elif Member ['memberstatus'] = 3: # added to the blacklist BlockedList. append (Member ['username']) state = responseState ('createchatroom ', dic ['baseresponse']) return ChatRoomName, DeletedList, BlockedListdef deleteMem Ber (ChatRoomName, UserNames): url = base_uri + \ '/webwxupdatechatroom? Fun = delmember & pass_ticket = % s' % (pass_ticket) params = {'baserequest ': BaseRequest, 'chatroomname': ChatRoomName, 'delmemberlist ':','. join (UserNames),} request = getRequest (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace ') # print (data) dic = json. loads (data) state = ResponseState ('deleteember', dic ['baseresponse']) return statedef addMember (ChatRoomName, UserNames): url = base_uri + \ '/webwxupdatechatroom? Fun = addmember & pass_ticket = % s' % (pass_ticket) params = {'baserequest ': BaseRequest, 'chatroomname': ChatRoomName, 'addmemberlist ':','. join (UserNames),} request = getRequest (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace ') # print (data) dic = json. loads (data) MemberLi St = dic ['memberlist'] DeletedList = [] BlockedList = [] for Member in MemberList: if Member ['memberstatus'] = 4: # DeletedList is deleted by the other party. append (Member ['username']) elif Member ['memberstatus'] = 3: # added to the blacklist BlockedList. append (Member ['username']) state = responseState ('addmember', dic ['baseresponse']) return DeletedList, BlockedListdef syncKey (): syncKeyItems = ['% s _ % s' % (item ['key'], item ['val']) for item in SyncKey ['LIST'] SyncKeyStr = '|'. join (SyncKeyItems) return SyncKeyStrdef syncCheck (): url = push_uri + '/synccheck? 'Params = {'skey': BaseRequest ['skey'], 'sid': BaseRequest ['sid'], 'uin': BaseRequest ['uin'], 'deviceid': BaseRequest ['deviceid'], 'synckey ': synckey (), 'r': int (time. time (),} request = getRequest (url = url + urlencode (params) response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace ') # print (data) # window. synccheck = {retcode: "0", selector: "2"} regx = r'window. synccheck = {retcode :" (\ D +) ", selector:" (\ d +) "} 'pm = re. search (regx, data) retcode = pm. group (1) selector = pm. group (2) return selectordef webwxsync (): global SyncKeyurl = base_uri + '/webwxsync? Lang = zh_CN & skey = % s & sid = % s & pass_ticket = % s' % (BaseRequest ['skey '], BaseRequest ['sid'], quote_plus (pass_ticket )) params = {'baserequest ': BaseRequest, 'synckey': SyncKey, 'r1 ':~ Int (time. time (),} request = getRequest (url = url, data = json. dumps (params) request. add_header ('contenttype', 'application/json; charset = UTF-8 ') response = wdf_urllib.urlopen (request) data = response. read (). decode ('utf-8', 'replace ') # print (data) dic = json. loads (data) SyncKey = dic ['synckey '] state = responseState ('webxsync', dic ['baseresponse']) return statedef heartBeatLoop (): while True: selector = syncCh Eck () if selector! = '0': webwxsync () time. sleep (1) def main (): try: ssl. _ create_default_https_context = ssl. _ create_unverified_contextopener = wdf_urllib.build_opener (wdf_urllib.HTTPCookieProcessor (CookieJar () opener. addheaders = [('user-agent', 'mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) chrome/44.0.2403.125 Safari/537.36 ')] wdf_urllib.install_opener (opener) release T: passif not g EtUUID (): print ('failed to get uuid ') returnprint ('getting QR code image...') showQRImage () time. sleep (1) while waitForLogin ()! = '000000': passos. remove (QRImagePath) if not login (): print ('logon failed') returnif not webwxinit (): print ('initialization failed') returnMemberList = webwxgetcontact () print ('Enable heartbeat thread') thread. start_new_thread (heartBeatLoop, () MemberCount = len (MemberList) print ('contacts Total % s friends '% MemberCount) chatRoomName = ''result = [] d = {} for Member in MemberList: d [Member ['username'] = (Member ['nickname']. encode ('utf-8'), Member ['remarkname']. encod E ('utf-8') print ('start searching... ') group_num = int (math. ceil (MemberCount/float (MAX_GROUP_NUM) for I in range (0, group_num): UserNames = [] for j in range (0, MAX_GROUP_NUM ): if I * MAX_GROUP_NUM + j> = MemberCount: breakMember = MemberList [I * MAX_GROUP_NUM + j] UserNames. append (Member ['username']) # create a group/Add a Member if ChatRoomName = '':( ChatRoomName, DeletedList, BlockedList) = createChatroom (UserNames) else :( Delet EdList, BlockedList) = addMember (ChatRoomName, UserNames) # todo BlockedList blacklisted DeletedCount = len (DeletedList) if DeletedCount> 0: result + = DeletedList # Delete member deletember (ChatRoomName, userNames) # progress bar progress = MAX_PROGRESS_LEN * (I + 1)/group_numprint ('[', '#' * progress, '-' * (MAX_PROGRESS_LEN-progress), ']', end = '') print ('new found that you have been deleted by % d '% DeletedCount) for I in range (DeletedCount): if d [Delet EdList [I] [1]! = '': Print (d [DeletedList [I] [0] + '(% s)' % d [DeletedList [I] [1]) else: print (d [DeletedList [I] [0]) if I! = Group_num-1: print ('continues searching. Please wait... ') # time to wait for the next interface call. sleep (INTERFACE_CALLING_INTERVAL) # todo deletes the group print ('\ n results are summarized, and retry after 20 s... ') resultNames = [] for r in result: if d [r] [1]! = '': ResultNames. append (d [r] [0] + '(% s)' % d [r] [1]) else: resultNames. append (d [r] [0]) print ('---------- list of deleted friends (% d in total) ----------' % len (result )) # filter emojiresultNames = map (lambda x: re. sub (r'', '', x), resultNames) if len (resultNames): print ('\ n '. join (resultNames) else: print ("NONE") print ('---------------------------------------------') # fixed the encoding problem in windows # http://blog.csdn.net/heyuxuanzee/article/details/8442718class UnicodeStreamFilter: def _ init _ (self, target): self.tar get = targetself. encoding = 'utf-8' self. errors = 'replace 'self. encode_to = self.tar get. encodingdef write (self, s): if type (s) = str: s = s. decode ('utf-8') s = s. encode (self. encode_to, self.errors).decode(self.encode_tow.self.tar get. write (s) if sys. stdout. encoding = 'cp936': sys. stdout = UnicodeStreamFilter (sys. stdout) if _ name _ = '_ main _': print ('the query results of this program may cause some psychological discomfort, please be careful when using... ') main () print ('enter key to exit... ')

The above describes how to implement search based on Python to check who deleted the content. I hope it will be helpful to you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.