Qzone-Delete

今天逛github发现了一些有关QQ的好玩的东西分享给大家~

QQ空间说说删除(from:https://github.com/Passkou/ClearQzoneEmotions)

  1. 下载chrome driver

记得要把driver和脚本放在同一个文件夹下,否则需要自己修改路径。

打包的exe文件链接:https://share.weiyun.com/5QLi0AC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from selenium import webdriver as web
from requests import get, post
import json
import time
from os import path


def get_g_tk(p_skey):
hashes = 5381
for letter in p_skey:
hashes += (hashes << 5) + ord(letter)
return hashes & 0x7fffffff


def del_dt(tid):
data = {
"hostuin": qq,
"tid": tid,
"t1_source": 1,
"code_version": 1,
"format": "fs",
"qzreferrer": r"https://user.qzone.qq.com/%s/infocenter" % qq
}
params = {
"g_tk": g_tk
}
post(url="https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6",
params=params, data=data, cookies=cookie
)


def get_dt():
params = {
"uin": qq,
"inCharset": "utf-8",
"outCharset": "utf-8",
"hostUin": qq,
"notice": "0",
"sort": "0",
"pos": "0",
"num": "20",
"cgi_host": "https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6",
"code_version": "1",
"format": "jsonp",
"need_private_comment": "1",
"g_tk": g_tk
}
req = get("https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6", params=params, cookies=cookie)
text = req.content.decode("utf-8")
text = text.replace("_Callback(", "")
text = text[:-2]
js = json.loads(text)
msg_list = js["msglist"]
if msg_list is None:
return False, []
m_list = []
for msg in msg_list:
tid = msg["tid"]
content = msg["content"]
localtime = time.localtime(msg["created_time"])
t = time.strftime("%Y/%m/%d %H:%M", localtime)
m_list.append((tid, t, content))
return True, m_list


def run():
global g_tk, cookie, qq
if not path.isfile("chromedriver.exe"):
print("chromedriver.exe 文件不存在!")
return
driver = web.Chrome("chromedriver.exe")
driver.get("https://qzone.qq.com/")
input("完成登录后按回车继续...")
cookies = driver.get_cookies()
cookie = {}
for c in cookies:
name = c["name"]
value = c["value"]
cookie[name] = str(value)
p_skey = cookie["p_skey"]
qq = cookie["uin"][1:]
print("你的QQ号:%s" % qq)
g_tk = get_g_tk(p_skey)
confirm = False
while True:
gt = get_dt()
if gt[0]:
msg_list = gt[1]
for msg in msg_list:
if not confirm:
c = input("已成功获取到说说,确认删除?(输入大写Y确认):")
if c == "Y":
confirm = True
else:
exit()
print("正在删除说说:%s %s" % (msg[1], msg[2]))
del_dt(msg[0])
pass
else:
print("说说已清空")
break
driver.close()


print("""====================
欢迎使用 自动清空QQ空间说说 程序!
版本:V1.0
制作:Passkou
bilibili:https://space.bilibili.com/12440199
====================""")
run()
input("按回车键退出...")

QQ留言删除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time


class Delete:

def __init__(self):
self.__u = '你的QQ'
self.__p = '你的密码'
self.__driver = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\Application\chromedriver')

# 登录qq空间
def login(self):
# driver.get 方法会打开请求的URL,WebDriver 会等待页面完全加载完成之后才会返回,
# 即程序会等待页面的所有内容加载完成,JS渲染完毕之后才继续往下执行。
# 注意:如果这里用到了特别多的 Ajax 的话,程序可能不知道是否已经完全加载完毕。
self.__driver.get("https://qzone.qq.com")
self.__driver.switch_to.frame('login_frame')
self.__driver.find_element_by_id('switcher_plogin').click()
self.__driver.find_element_by_id('u').send_keys(self.__u)
self.__driver.find_element_by_id('p').send_keys(self.__p)
self.__driver.find_element_by_id('login_button').click()
# 从frame返回
self.__driver.switch_to.default_content()

def switch2board(self):
# 找到留言板按钮
WebDriverWait(self.__driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//a[@title="留言板"]'))
).click()

# 黄钻过期提醒
# WebDriverWait(self.__driver, 10).until(
# EC.presence_of_element_located((By.ID, "dialog_button_1"))
# ).click()

# 确保留言板所在的frame已经加载完并切换
WebDriverWait(self.__driver, 10).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[@id="tgb"]'))
)

def getTotalPage(self):
# 页数为一页的时候没有a标签
try:
# 为什么
# totalPage = driver.find_element_by_xpath('//span[@class="mod_pagenav_count"]/a[last()]').text
# 为什么输出为空,text属性不是文本内容?? 还是说是谷歌浏览器的问题??
return int(self.__driver.find_element_by_xpath('//span[@class="mod_pagenav_count"]/a[last()]')
.get_attribute('innerHTML'))
except EC.NoSuchElementException:
return 1

# 点击确定删除按钮,并回到留言板的frame
def handlePopWin(self, selectedItem=None):
# 弹窗不在frame中
self.__driver.switch_to.default_content()
WebDriverWait(self.__driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//a[@class="qz_dialog_layer_btn qz_dialog_layer_sub"]'))
).click()
if selectedItem:
print('删除 %d 条记录' % selectedItem)
else:
print('删除一页记录')

# 确保留言板所在的frame已经加载完并切换
WebDriverWait(self.__driver, 10).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[@id="tgb"]'))
)

# 删除所有的留言
def deleteAll(self):
# totalPage = self.getTotalPage()

# # 留言板设置的sub_lsit
# WebDriverWait(driver, 10).until(
# EC.presence_of_element_located((By.XPATH, '//ul[@class="sub_list bg bor"]'))
# )
# # getElementsByClassName返回的是集合
# driver.execute_script('document.getElementsByClassName("sub_list bg bor")[0].style.display="block"')
# # 进入批量管理
# driver.find_element_by_id('btnBatch').click()

for i in range(self.getTotalPage()):
time.sleep(3)
# 执行js语句可以直接设置id=divBatchOper元素的可见性来进入批量管理
self.__driver.execute_script('document.getElementById("divBatchOper").style.display="block"')
self.__driver.find_element_by_id('chkSelectAll').click()
self.__driver.find_element_by_id('btnDeleteBatchBottom').click()
self.handlePopWin()

# 删除指定qq的留言
def deleteByNum(self, num):
# 显示批量管理
self.__driver.execute_script('document.getElementsByClassName("sub_list bg bor")[0].style.display="block"')
self.__driver.find_element_by_id('btnBatch').click()
while True:
time.sleep(3)
selectedItem = 0
# 找到该页中所有的留言
for li in self.__driver.find_elements_by_xpath('//li[@class="bor3"]'):
# 如果输入的qq号在标签内,说明是该qq的留言,选中该条留言
if num in li.get_attribute('innerHTML'):
li.find_element_by_class_name('item_check_box').click()
selectedItem += 1

# 滚动到顶部
self.__driver.execute_script('parent.scrollTo(0,200)')
# 该页中确实有目标qq的留言才进行删除
if selectedItem != 0:
# 点击 删除选中的 按钮
self.__driver.find_element_by_id('btnDeleteBatchBottom').click()
self.handlePopWin(selectedItem)
# 该页中没有目标qq的留言处理下一页
else:
nextBtn = WebDriverWait(self.__driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//div[@id="pager_top"]//p[@class="mod_pagenav_main"]/a[last()]'))
)
# print(nextBtn.get_attribute('class'))
# nextBtn = self.__driver.find_element_by_xpath('//div[@id="pager_top"]//p[@class="mod_pagenav_main"]/a[last()]')
# 还有下一页
if nextBtn.get_attribute('class') == 'c_tx' or nextBtn.get_attribute('class') == 'c_tx ':
print('切换到下一页!')
nextBtn.click()
elif nextBtn.get_attribute('class') == 'c_tx none':
return

def start(self, num=None):
self.login()
self.switch2board()
if num:
self.deleteByNum(num)
else:
self.deleteAll()
print('删除完成')
self.__driver.quit()

if __name__ == '__main__':
# delete = Delete()
# delete.start()
delete = Delete()
delete.start()

马上情人节了,送大家一个二维码每日情话8

1Hc2JP.png

坚持原创技术分享,您的支持将鼓励我继续创作!