你是否也有過,想删除QQ空間裡某個人的對自己發表的說說的全部評論,但又因說說太多,手動查找再删除太過麻煩?OK,我也有這個需求,成品分享給你。
如果想自己琢磨呢,源碼在文末;如果想直接使用呢,exe已上傳,不用積分即可下載下傳。
一、使用本程式,需要提供4個内容:你的QQ号、對方的名稱、g_tk和cookie。
1、你的QQ号
就是你的QQ号,複制到conf.json檔案
2、對方的名稱
要删除的對方的備注或昵稱(ta在你空間所顯示的名稱),一般如果你設定了備注,就是備注名;沒設定備注,就是他的網名。複制到conf.json檔案。可以多個好友,以英文逗号分隔。
3、g_tk
a. 首先手動登陸你的QQ空間
b. 點進“我的首頁”

c. 按F12,選中network(有的浏覽器顯示是“網絡”)
d. 重新整理一下浏覽器,點選有html的一項
e. 最下面就有g_tk了,複制到conf.json檔案
界面先不要關
4、cookie
g_tk擷取完,上面就有cookie,複制到conf.json檔案
二、運作程式
三、源碼
import time
import requests
import json
with open('conf.json', 'r', encoding='utf-8') as f:
content = f.read()
msg = json.loads(content)
print(msg)
# 你的QQ号
QQ = msg['QQ']
# 浏覽器打開QQ空間,按F12,找到g_tk
g_tk = msg['g_tk']
# 要删除的對方的備注或昵稱(ta在你空間所顯示的名稱)
targetname = msg['name'].split(',')
# 浏覽器打開QQ空間,按F12,找到cookie
cookie = msg['cookie']
print('@'*60)
print('>> 你的QQ:', QQ)
print('>> 對方名稱:', targetname)
print('@'*60)
print('>> 開始運作')
print()
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
'cookie': cookie
}
def getcomment():
delcnt = 0
delmsg = []
totalcomment = 20
pos = 0
while pos < totalcomment:
print('#' * 60)
print(">> 目前位置:", pos)
url = 'https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin={0}&inCharset=utf-8&outCharset=utf-8&hostUin={0}¬ice=0&sort=0&pos={1}&num=20&cgi_host=https%3A%2F%2Fuser.qzone.qq.com%2Fproxy%2Fdomain%2Ftaotao.qq.com%2Fcgi-bin%2Femotion_cgi_msglist_v6&code_version=1&format=json&need_private_comment=1&g_tk={2}'.format(QQ, pos, g_tk)
pos += 20
html = requests.get(url, headers=headers).json()
totalcomment = int(html['total'])
print('>> 總共條數:', totalcomment)
msglist = html['msglist']
for item in msglist:
try:
commentlist = item['commentlist']
conlist = item['conlist']
if conlist:
conlist = conlist[0]['con']
print(">> 釋出的說說:", conlist)
else:
print(">> 釋出僅為圖檔")
topicId = QQ+'_' + item['tid']
print(">> topicId:", topicId)
for i in commentlist:
content = i['content']
name = i['name']
createTime = i['createTime']
commentId = commentlist.index(i)+1
print(">> 評論{}: ({}){}\t{}".format(commentId, createTime, name, content))
if name in targetname:
print(">> 删除本條留言")
delcomment(topicId, commentId)
delcnt += 1
delmsg.append(content)
print()
except:
pass
time.sleep(1)
print('*' * 60)
print('共删除條數:', delcnt)
print('共删除内容:', delmsg)
print('*' * 60)
def delcomment(topicId, commentId):
url = 'https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delcomment_ugc?g_tk={0}'.format(g_tk)
data={
'uin': QQ,
'hostUin': QQ,
'topicId': topicId,
'commentId': commentId,
'inCharset':'',
'outCharset':'',
'ref':'',
'hostuin': QQ,
'code_version': '1',
'format': 'fs',
'qzreferrer': 'https://user.qzone.qq.com/proxy/domain/qzs.qq.com/qzone/app/mood_v6/html/index.html#mood&g_iframeUser=1&g_iframedescend=1&uin={0}&pfid=2&qz_ver=8&appcanvas=0&qz_style=31¶ms=&entertime=1588985689146&canvastype=&cdn_use_https=1'.format(QQ)
}
html = requests.post(url, headers=headers, data=data)
time.sleep(1)
html = requests.post(url, headers=headers, data=data)
if '對不起,原文已經被删除,無法檢視' in html.text:
print('原文已經被删除')
try:
getcomment()
except Exception as e:
print(e)
input(">> 任意鍵退出...")