Preface:

Source I would like to put their own before the micro blog account in the micro blog are deleted, no more nonsense, let us begin happily

The development tools

Python version: 3.6.4

Related modules:

DecryptLogin module;

The argparse module;

And some of the modules that come with Python.

Environment set up

Install Python and add it to the environment variable, and the PIP will install the appropriate module.

Introduction of the principle

The principle is actually quite simple. First of all, we use the open source DecryptLogin library to implement the simulated login operation of Weibo:

From DecryptLogin import login @staticmethod def login(username, password): lg = login.Login() infos_return, session = lg.weibo(username, password, 'pc') return infos_return, session

Then, all we need to do is constantly get all the micro blog IDs of our home page:

"' get a user home page list of weibo ' 'def __getweibolist (self) : url =' https://weibo.com/p/aj/v6/mblog/mbloglist 'params = {' ajwvr' : '6', 'domain': '100505', 'is_search': '0', 'visible': '0', 'is_all': '1', 'is_tag': '0', 'profile_ftype': '1', 'page': '1', 'pagebar': '1', 'pl_name': 'Pl_Official_MyProfileFeed__19', 'id': f'100505{self.user_id}', 'script_uri': f'/{self.user_id}/profile', 'feed_type': '0', 'pre_page': '5', 'domain_op': '100505', '__rnd': str(time.time()*1000)[:13] } response = self.session.get(url, params=params) data = response.json()['data'] weibo_mids = re.findall(r'\s+mid="(\d+)"\s+', data) return weibo_mids

And according to these micro blog ID to batch delete these micro blog is OK:

"" def run(self): user_input = input(" Do you really want to delete all your tweets? (yes/no):') if not (user_input.lower() == 'yes' or user_input.lower() == 'y'): return url = 'https://weibo.com/aj/mblog/del?ajwvr=6' headers = { 'Referer': f'http://weibo.com/{self.user_id}/profile?rightmod=1&wvr=6&mod=personnumber&is_all=1' } del_count = 0 total_count = 0 while True: weibo_mids = self.__getweibolist() if not weibo_mids: break for mid in weibo_mids: Total_count += 1 print('[INFO]: '... ' % (total_count, del_count)) response = self.session.post(url, data={'mid': mid}, headers=headers) if response.json()['code'] == '100000': del_count += 1 time.sleep(random.randrange(1, 3)+random.random()) time.sleep(random.randrange(3, 6)+random. Random ()) print('[INFO]: %s of your account is detected, and %s of your account has been deleted successfully... ' % (total_count, del_count))

This is the end of the article, thank you for watching, follow me every day to share the Python simulation login series, the next article to share batch delete about.

To thank you readers, I’d like to share with you some of my recent collection of dry programming goodies and give something back to every reader in the hope of helping you out.

Dry goods mainly include:

① More than 2000 Python e-books (mainstream and classic books are available)

(2) The Python Standard Library (Chinese version)

③ project source code (40 or 50 interesting and classic hands-on project and source code)

④Python basic introduction, crawler, web development, big data analysis video (suitable for small white learning)

⑤ Python Learning Roadmap (Goodbye to Slow Learning)

All done~ complete source code + dry goods see personal profile or private message to obtain the relevant files.