Python allows you to easily find and delete your WeChat friends.

Source: Internet
Author: User
This article describes how to quickly view the number of friends deleted by a python script. For more information, see Preface

I believe you will have received such a group of text messages, and it is said that it is also classified as one of the five tips for fun. However, you only need to run the script, you can easily find and delete your friends.

Principle

Create a group. If a group cannot be added, it is deleted as a friend (do not speak in the group, others cannot see it ).
The webpage interface is used, but there are still some minor problems, but now the result seems to be missing a small part, for unknown reasons ...... I have never tried to get hacked. In the end, only one group is left behind. You need to delete it manually.

Method

Download the python script and run it. Start Terminal and switch to the file directory:

Python wdf. py
The Code is as follows:

#! /Usr/bin/env python # coding = utf-8import osimport urllib, 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 da Ta global 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 Order Traversal, or 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', 'officia Laccounts ', '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) ChatRo OmName = 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 ['base Response'] ['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 [' 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 DeletedListdef main (): opener = urllib2.build _ opener (urllib2.HTTPCookieProcessor (cookielib. cookieJar () urllib2.install _ opener (opener) if getUUID () = False: print 'failed to get uuid 'Return sho WQRImage () 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 ()

Umeng

The test is effective. 11 of my "friends" are deleted and are silently classified as 11 dating male. Are there any more serious injuries than me?

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.