Preface:

Python delete QQ space to talk about the tutorial. Without further ado, let’s begin happily

The development tools

Python version: 3.6.4

Related modules:

DecryptLogin module;

The argparse module;

And some modules that come with Python.

Environment set up

Install Python and add it to the environment variables. PIP installs the required related modules.

Introduction of the principle

Like before, we will use our open source DecryptLogin package to implement a wave of simulated login operations in Qzone:

from DecryptLogin import login

@staticmethod
def login() :
    lg = login.Login()
    infos_return, session = lg.QQZone()
    return session
Copy the code

Then, we go to Qzone to grab a wave of packages, that is, after entering Qzone, press F12 to open the developer tool, and then click the “Talk” button, you can find the following link:

That is:

https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?
Copy the code

It returns the talk data from the talk page. A brief analysis of what parameters this link should carry:

1.Easy to know parameter uIN: user QQ number ftype: can always be'0'Sort: can always be'0'Pos: Can always be'0'Num: The value can always be'20'Replynum: Can always be'100'Callback: Can always be'_preloadCallback'Code_version: Can always be'1'
format: can always be'jsonp'Need_private_comment: The value can always be'1'
2.The g_tk qzoneToken argument is not knownCopy the code

Where g_tk we said in a previous article how to calculate it:

Simulation log series 1 | login login QQ space simulation series 2 | login QQ space simulation

Find the corresponding js code:

And then convert to py:

"' computing g_tk" '
def __calcGtk(self, string) :
    e = 5381
    for c in string:
        e += (e << 5) + ord(c)
    return 2147483647 & e
Copy the code

As for the parameter qzoneToken, we can also find the corresponding JS code:

It turns out it could be a fixed value. Write a simple program to test it:

"Get home page talk data."
def __getAllTwitters(self) :
    url = 'https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?'
    params = {
                'uin': self.uin,
                'ftype': '0'.'sort': '0'.'pos': '0'.'num': '20'.'replynum': '100'.'g_tk': self.g_tk,
                'callback': '_preloadCallback'.'code_version': '1'.'format': 'jsonp'.'need_private_comment': '1'.'qzonetoken': '12a2df7fc3ce126e67c62b0577cdea5133e79e77f46ae920b2a8b822ac867e54416698be9ee883f09e'
            }
    response = self.session.get(url, params=params)
    response_json = response.content.decode('utf-8').replace('_preloadCallback('.' ') : -2]
    response_json = json.loads(response_json)
    msglist = response_json['msglist']
    if msglist is None:
        msglist = []
    all_twitters = {}
    for item in msglist:
        tid = item['tid']
        created_time = item['created_time']
        content = item['content']
        all_twitters[tid] = [created_time, content]
    return all_twitters
Copy the code

You can see that the returned data is as follows:

The data on our front page is correct:

It seems that our previous analysis is entirely correct. Now, we just need to capture the packet to see which interface needs to be deleted.

You need to carry the following parameters:

Hostuin: The user's QQ id. Tid: YesidT1_source: a fixed value'1'Code_version: a fixed value'1'
formatFixed value:'fs'Qzreferrer: format for'https://user.qzone.qq.com/ #} {user QQ/infocenter'
Copy the code

So now we can happily start writing code:

"External call"
def run(self) :
    url = 'https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?'
    del_count = 0
    total_count = 0
    while True:
        all_twitters = self.__getAllTwitters()
        if not all_twitters:
            break
        for key, value in all_twitters.items():
            total_count += 1
            print('[INFO]: processing %s comment, successfully deleted %s comment... ' % (total_count, del_count))
            if self.is_manual:
                print('Time: %s, content: %s... ' % (str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(value[0]))), value[1]))
                user_input = input('Do I need to delete this clause? (yes/no):')
                if user_input.lower() == 'n' or user_input.lower() == 'no':
                    continue
            data = {
                        'hostuin': self.uin,
                        'tid': key,
                        't1_source': '1'.'code_version': '1'.'format': 'fs'.'qzreferrer': f'https://user.qzone.qq.com/{self.uin}/infocenter'
                    }
            params = {
                        'qzonetoken': self.qzonetoken,
                        'g_tk': self.g_tk
                    }
            try:
                response = self.session.post(url, data=data, params=params)
                del_count += 1
                time.sleep(random.randrange(1.3)+random.random())
            except:
                pass
        time.sleep(random.randrange(3.6)+random.random())
    print('[INFO]: %s entries in your account have been successfully deleted... ' % (total_count, del_count))
Copy the code

This is the end of the article, thank you for watching, follow me every day to share the Python simulation login series, next article to share the terminal to see the netease cloud daily song recommendations.

To thank you readers, I’d like to share some of my recent programming favorites to give back to each and every one of you in the hope that they can help you.

Dry goods mainly include:

① Over 2000 Python ebooks (both mainstream and classic books should be available)

②Python Standard Library (Most Complete Chinese version)

③ project source code (forty or fifty interesting and classic practice projects and source code)

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

⑤ A Roadmap for Learning Python

All done~ Complete source code + dry plus Python novice learning exchange community: 594356095