This is the 29th day of my participation in the First Challenge 2022

Seriously, WHEN I wrote this script, I didn’t know all of Python’s basic syntax. All I can say is, language doesn’t matter, just use it…

As for why want to delete QQ dynamic, just do not want to always see that year today those once sent very childish words, dynamic and many (although these years have not used QQ), with the hand is too laborious, want to write a script automatic processing.

To delete all the dynamics, I need to do two things:

  1. Get all the dynamic information

  2. Just get the deleted URL, iterate over all the retrieved dynamics, and then delete them all.

In addition, there is a big problem: you need to get the session information first. This simple, after all, is their own QQ, direct login and then, what not on the browser.

Of course, that’s easy to say, but easy to do… It’s pretty simple.

I originally wanted to use shell to solve, but later I grabbed the dynamic information and found it was JSON. On second thought, I decided python should be easier to use (just spend a couple of hours studying Python syntax).

Here we go:

  1. Log in to Qzone and click “Talk”. The first step is to find the URL that can get the dynamic information list. Here I will tell you the results of my analysis, there is a page number under the dynamic, click on the URL is, here is an example:
https://h5.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=763795151&inCharset=utf-8&outChars et=utf-8&hostUin=763795151&notice=0&sort=0&pos=840&num=20&cgi_host=http%3A%2F%2Ftaotao.qq.com%2Fcgi-bin%2Femotion_cgi_ms glist_v6&code_version=1&format=jsonp&need_private_comment=1&g_tk=635656033&qzonetoken=8f1208fd31ba56f14fb6f71f498501c179 fde08e0a6866589e12672dc8fe8c2af00b924c63f35cCopy the code

Pos: the number of rows to start with, num: the number of rows to get. Adjust the values of these two parameters as needed.

Then, put that URL in the browser and make a request, I use Google. Then pull out the headers, cookies, and so on. Dynamic information can be retrieved based on pos and num values. The result is a string, and the middle part is a Json string.

I’ve already deleted it, I’m not going to give you an example, but I’m going to describe the string, and there’s a field in this JSON string msglist which is a list, maybe empty, and when it’s not empty, each value has a field tid, and the value of tid is a query parameter that we need to use to delete this dynamic. Save each dynamic TID and delete it after traversing.

  1. Gets the deleted URL. It’s as simple as deleting one and pulling out the deleted request information (check your browser). This is a POST method that gets the URL, request header, cookie, and request parameters used in the deletion. Then configure it.

  2. Iterate over all the tiDs obtained in 1, then set each TID to the parameters in the request to be deleted, and delete them in turn.

It’s not complicated. It’s not technical. I’ll post my implementation below, since it’s my first time using Python and I don’t know if I’m doing it right.

Code:

#! /usr/bin/python

import requests
import re
import json

# total number of dynamics to delete
total=840
limit=10
pages=total/limit
start_pos=2
tids=[]
Json is used as a regex
pattern=re.compile(r'^_Callback((.*)); $')
Get all dynamic tiDs
cookie="Replace the cookie in your browser."
# request header
request_headers={'authority':'h5.qzone.qq.com'.'method':'GET'.'path':'/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=763795151&inCharset=utf-8&outCharset=utf-8&hostUin=76379 5151&notice=0&sort=0&pos=820&num=40&cgi_host=http%3A%2F%2Ftaotao.qq.com%2Fcgi-bin%2Femotion_cgi_msglist_v6&code_version= 1&format=jsonp&need_private_comment=1&g_tk=1874324779&qzonetoken=98cd2ff9067f620f90a72cbe07da56012b4593659ebbf1deba0b350 e82d53be364cd48d038e7ca'.'scheme':'https'.'accept':'text/html,application/xhtml+xml,application/xml; Q = 0.9, image/webp image/apng, * / *; Q = 0.8, application/signed - exchange; v=b3'.'accept-language':'zh-CN,zh; Q = 0.9, en - US; Q = 0.8, en. Q = 0.7 '.'cache-control':'max-age=0'.'cookie':cookie, 'upgrade-insecure-requests':'1'}
def getTids(say_list_url) :
    res=requests.get(say_list_url, headers=request_headers)
    text=pattern.findall(res.text)[0]
    resolveTid(text)
    print "tid len: %d" % (len(tids))
    
def resolveTid(text) :
    jsonObj=json.loads(text)
    if  not jsonObj.has_key('msglist') :
        print text
        return False
    msglist=jsonObj['msglist']
    if  msglist is None :
        return False
    for msg in msglist:
        print "tid: %s" % (msg['tid'])
        tids.append(msg['tid'])

for page in range(pages):
    num=limit*page
    Set pos and num values dynamically to get all the information
    say_list_url="https://h5.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=763795151&inCharset=utf-8&outChar set=utf-8&hostUin=763795151&notice=0&sort=0&pos=%d&num=%d" % (start_pos+num, limit) + "&cgi_host=http%3A%2F%2Ftaotao.qq.com%2Fcgi-bin%2Femotion_cgi_msglist_v6&code_version=1&format=jsonp&need_private_commen t=1&g_tk=1168850316&qzonetoken=87520ec2a71a9f349d23d7e462ffdef0bc3075786bc42114239de62af56e92ca85ccb2eb098144" 
    getTids(say_list_url)

print "total: %d" % (len(tids))
print "start delete..."

Delete the url and replace it with your own
delete_url="https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?qzonetoken=fc557d5f5542fbb9514 79b8e8b2f1a0f163db952eb44cef275261b76b758edeb51c34834c16f80&g_tk=597814207"
delete_cookie="Change your browser's cookie."
# Change your own
delete_headers={'authority':'user.qzone.qq.com'.'method':'POST'.'path':'/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?qzonetoken=9a40f79cdd9908ccbd41466b3b2276314f155525357a e4fb8a7d90093f6379e5144d31eefeabc6&g_tk=597814207'.'scheme':'https'.'accept':'* / *'.'accept-language':'zh-CN,zh; Q = 0.9, en - US; Q = 0.8, en. Q = 0.7 '.'content-length':'178'.'content-type':'application/x-www-form-urlencoded; charset=UTF-8'.'origin':'https://user.qzone.qq.com'.'referer':'https://user.qzone.qq.com/763795151/311'.'cookie': delete_cookie, 'user-agent':'the Mozilla / 5.0 (Linux; The Android 6.0. Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Mobile Safari/537.36'}
body={'hostuin':'763795151'.'t1_source':'1'.'code_version':'1'.'format':'fs'.'qzreferrer':'https://user.qzone.qq.com/763795151/311'.'tid':' '}
for tid in tids:
    body['tid']=tid
    print body
    dr=requests.post(delete_url, data=body, headers=delete_headers)
    print dr
Copy the code

If the session information has been invalid for too long, log in again and update it, as the web knows. If 403 appears, the configuration is incorrect. Make sure headers, cookies, and urls are not copied incorrectly.

This is the first program I’ve written in Python, and it’s not Hello,world.

The above script I was executed, is indeed my space for many years of dynamic once all finished. Later, the girl who shared the apartment next door heard me say this, and wanted me to help her to clear it, but I tried, I don’t know why I can’t clear hers all at once. And then I gave up, and I didn’t get into the details.