让代码更简单

Python批量删除QQ空间说说

重要:本文最后更新于2023-07-16 17:39:56,某些文章具有时效性,若有错误或已失效,请在下方留言或联系代码狗

前几天找到一个使用浏览器执行JavaScript,模拟人工点击删除的方法删除QQ空间说说(QQ空间批量删说说日志代码),这种方法需要自己翻页,狗哥很不喜欢,于是看了下删除请求数据表,使用python写了个批量删除QQ空间说说的简单程序,大概一次可以删除一百条左右。

复制
import requests
import json,re,time

uin='你的QQ号'
g_tk='请求地址中获得'
cookie='你的cookie'
def getlist(cookie,uin,g_tk):
    url = "https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=1016134519&ftype=0&sort=0&pos=0&num=40&replynum=100&g_tk="+g_tk+"&callback=_preloadCallback&code_version=1&format=jsonp&need_private_comment=1&g_tk="+g_tk

    payload='uin=%20'+uin+'&ftype=%200&sort=%200&pos=%200&num=%2040&replynum=%20100&g_tk=%20'+g_tk+'&callback=%20_preloadCallback&code_version=%201&format=%20jsonp&need_private_comment=%201&g_tk=%20'+g_tk
    headers = {
      'Host': 'user.qzone.qq.com',
      'Connection': 'keep-alive',
      'Content-Length': '140',
      'Pragma': 'no-cache',
      'Cache-Control': 'no-cache',
      'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
      'sec-ch-ua-platform': '"Windows"',
      'sec-ch-ua-mobile': '?0',
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
      'Content-Type': 'application/x-www-form-urlencoded',
      'Accept': '*/*',
      'Origin': 'https://user.qzone.qq.com',
      'Sec-Fetch-Site': 'same-origin',
      'Sec-Fetch-Mode': 'cors',
      'Sec-Fetch-Dest': 'empty',
      'Referer': 'https://user.qzone.qq.com/'+uin,
      'Accept-Encoding': 'gzip, deflate, br',
      'Accept-Language': 'zh-CN,zh;q=0.9',
      'Cookie': cookie
    }

    response = requests.request("POST", url, headers=headers, data=payload)
    json_data = re.search(r'_preloadCallback\((.*?)\);', response.text).group(1)
    data=json.loads(json_data)
    msglist=data['msglist']
    if len(msglist)>0:
      for i in range(0,len(msglist)):
          print(msglist[i]['tid'])
          if deldata(msglist[i]['tid'],uin,g_tk,cookie)==False:
              print("需要验证码")
              break
          time.sleep(3)
      if i==len(msglist)-1:
        getlist(cookie,uin,g_tk)
      else:
          print("终止")
    else:
        print("没有了")
def deldata(tid,uin,g_tk,cookie):
    url = "https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?&g_tk="+g_tk

    payload='hostuin='+uin+'&tid='+tid+'&t1_source=1&code_version=1&format=fs&qzreferrer=https%253A%252F%252Fuser.qzone.qq.com%252F'+uin
    headers = {
      'Host': 'user.qzone.qq.com',
      'Connection': 'keep-alive',
      'Content-Length': '140',
      'Pragma': 'no-cache',
      'Cache-Control': 'no-cache',
      'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
      'sec-ch-ua-platform': '"Windows"',
      'sec-ch-ua-mobile': '?0',
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
      'Content-Type': 'application/x-www-form-urlencoded',
      'Accept': '*/*',
      'Origin': 'https://user.qzone.qq.com',
      'Sec-Fetch-Site': 'same-origin',
      'Sec-Fetch-Mode': 'cors',
      'Sec-Fetch-Dest': 'empty',
      'Referer': 'https://user.qzone.qq.com/'+uin,
      'Accept-Encoding': 'gzip, deflate, br',
      'Accept-Language': 'zh-CN,zh;q=0.9',
      'Cookie': cookie
    }

    response = requests.request("POST", url, headers=headers, data=payload)


    json_data = re.search(r'frameElement\.callback\((.*?)\);', response.text).group(1)
    data=json.loads(json_data)
    if data['subcode']==0:
        print('删除成功:'+tid)
        return True
    else:
        print(json_data)
        return False

getlist(cookie,uin,g_tk)

将程序中的cookie和g_kt以及你自己的QQ号填进去,执行python脚本就行了。QQ空间cookie有几个是会话级别的,只要关闭网页过一会儿就会失效,因此在删除过程中不要关闭网页。

必须的参数获取过程

Python批量删除QQ空间说说

感觉很棒!可以赞赏支持我哟~

0 打赏

评论 (0)

登录后评论
QQ咨询 邮件咨询 狗哥推荐