MENU

Python检测抖音关注账号是否封号

2021 年 05 月 22 日 • 默认分类阅读设置

最近抖音关注到达上限5000个了,所以就导致很多漂亮小姐姐没办法关注
抖音关注上限
想到以前关注的小姐姐可能被封号了,所以就想把封号的小姐姐取消关注,但是让人头疼的是抖音没办法一键取消封号的抖音账号,在抖音APP只能不断地下滑,可是关注数量有5000个,怎么可能一点点去找,于是我想到了抖音创作服务平台,果然看到有关注管理,虽然这里可以翻页,但是一刷新,就回到最前面了,而且还是需要一个一个去看,那么就需要用到python了
首先是抓接口,很简单,打开审查元素刷新一下,第一个便是
抖音关注列表接口
接下来让我们看一下headers,请求是GET,让我们仔细看一下请求地址

https://creator.douyin.com/aweme/v1/creator/relation/following/list/?aid=2906&app_name=aweme_creator_platform&device_platform=web&referer=&user_agent=Mozilla%2F5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML,+like+Gecko)+Chrome%2F90.0.4430.212+Safari%2F537.36&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML,+like+Gecko)+Chrome%2F90.0.4430.212+Safari%2F537.36&browser_online=true&timezone_name=Asia%2FShanghai&cursor=1621674866&count=10&_signature=_02B4Z6wo00901lr-SsQAAIDB6g-mDUhK8rZa-k5AAPYlrhPn7GG8Zh1G7BiFM-Lw7ITcG7203IOPLVRGV2Y8D.qwxrw07ILdDZSexNKf4QgTlV9CbYzi3lXAC3E4.YI-MxR26HvLKxRoSdcJ97

很长对不对,其实只有两个关键参数,那就是countcursor,其中count是获取的数量,最大20,最小为1,而cursor则是返回中的参数,把返回参数的cursor放到下次请求的cursor中,即是下一页,不知道抖音为什么用这样反人类的设计,cursor默认可以是0
这样我们就可以获取到关注列表中的用户信息了,那么让我们再仔细看一下返回的json(为了方便,count为1)

{
    "cursor": 1621674721,
    "extra": {
        "now": 1621689135000
    },
    "has_more": true,
    "hotsoon_has_more": true,
    "hotsoon_text": "为尊重你的选择,因未授权向抖音同步你在抖音火山版的好友关系(包含关注等),部分用户暂不支持查看。授权后,你可以在抖音发现更多好友,并看到更多内容",
    "status_code": 0,
    "status_msg": "",
    "total_num": 0,
    "user_info_list": [{
        "avatar": "tos-cn-i-0813/7d0294fa7d8c4785b1cf76334704881f",
        "each_follow": true,
        "nickname": "酸奶",
        "signature": "我们不是春季限定 你就是我的春天\n不要连赞哇\n接陪玩  具体私 王者荣耀  和平精英\n粉丝群Q 197134700(进了就不要退了)",
        "user_id": "@jfRh6L9MRU76uMxZ57Ptv9V/oi6XZCj3KqskN6dau5oUauzfobhv23KjRfy/o7Vq"
    }]
}

可以看到关键信息有

字段名用途
cursor我们获取下一页的数字
avatar用户头像地址
nickname用户名称

那么我们如何判断一个用户是否被封号呢?我们对比一下一个正常用户的json和封号用户的json,发现唯一变的只有avatar,也就是头像的地址,封号的用户头像地址为c16000003f97583dac4,而且所有的封号账号头像地址均为此字符串,而注销的用户头像地址为b76600039bd12b4c09da,所以我们只需要判断avatar是否为这两个字符串即可,不过如果是只封了头像,好像也会是c16000003f97583dac4,所以不能100%判断正确,具体我也不清楚,问了一个是封号头像,但是并没有被删除作品的人,不过她并没有回复我,这渔网很nice
抖音
代码应该算是比较简单吧,反正我是新手,能用就行,先来看一下视频

源代码在下面

import requests
import json
import time

# 抖音创作者平台cookie
header = {'Cookie': 'MONITOR_WEB_ID=7a18a16d-df35-4848-a946-558bedada072; csrf_session_id=ec82491737de49549eebd13ac9250da2; csrf_token=zEmjTWzNTYmjiMbNtSMVRzjMtQbxpYGm; ttcid=61c014f7ba034d48b6d4d310888c460031; s_v_web_id=kotn5mh3_ediAAa1F_8kid_47Wl_9U3A_NcJw5dwD4NWq; passport_csrf_token_default=70d41121e18142ea501749084412d803; passport_csrf_token=70d41121e18142ea501749084412d803; n_mh=5K3uxU4jIPZqCFfezicea82fsDosTm2TAMqRtyvf_Y0; sso_uid_tt=b85defc601be19ab816215b4c334060a; sso_uid_tt_ss=b85defc601be19ab816215b4c334060a; toutiao_sso_user=5e4eaa21ef75a2ce6cca9e059ad93ea3; toutiao_sso_user_ss=5e4eaa21ef75a2ce6cca9e059ad93ea3; odin_tt=39d54b8d3b179444185f43a93cd8b734bdb851a106b181446d3ba0f326b8213e7d1edadaf061feea3ec4260f35b6faca778231b0eb975075fea14be65ebe09f2; passport_auth_status_ss=97a1cdbc98f0a483f9e2bcf8fbca5186%2C; sid_guard=588d1653fa90a8f687bfd7f363e8927f%7C1621318487%7C5184000%7CSat%2C+17-Jul-2021+06%3A14%3A47+GMT; uid_tt=37f6a26f178a0e063658ab0631217179; uid_tt_ss=37f6a26f178a0e063658ab0631217179; sid_tt=588d1653fa90a8f687bfd7f363e8927f; sessionid=588d1653fa90a8f687bfd7f363e8927f; sessionid_ss=588d1653fa90a8f687bfd7f363e8927f; passport_auth_status=97a1cdbc98f0a483f9e2bcf8fbca5186%2C; oc_login_type=LOGIN_PERSON; ttwid=1%7CrtVE98prXVXcTUCBkBsaTTijdvCmpL4bisSf5KFukN8%7C1621334066%7Cfbd5dbeec6aec6ff13dcdfc23442d5807d1b7347deb678f413e6c65be7c22c9a; tt_scid=ylXCflEjfwUVQIxT-wRmF7LZHOVOQtMIbjVrqW.ul-PObJoQsZih2WEgEVAvjdLo9061'}
shijian = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
sbdy = str(0)
sl = 0
file = open("D:/test.txt", "a+",encoding='utf-8')
file.write(shijian)
yczh = 0

print(str(shijian)+"\n开始检测,请耐心等待...")
while (sl < 5000):
    url = 'https://creator.douyin.com/aweme/v1/creator/relation/following/list/?aid=2906&app_name=aweme_creator_platform&device_platform=web&referer=https:%2F%2Fcreator.douyin.com%2Fcreator-micro%2Fhome&user_agent=Mozilla%2F5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML,+like+Gecko)+Chrome%2F90.0.4430.212+Safari%2F537.36&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML,+like+Gecko)+Chrome%2F90.0.4430.212+Safari%2F537.36&browser_online=true&timezone_name=Asia%2FShanghai&_signature=_02B4Z6wo00901TSjMlwAAIDChFLelrWwFwk0pzbAAC2OgYeyEeDw.eiDhwpfH.4NSilIGJd.pSZ5de4SL4e-U2DQy-VLvH0NkfwTIp14WBZCgv63l6pLIkqBZMs9VRrdqIj3xOjfyY.2y6v8de&cursor='+sbdy+'&count=20'
    r = requests.get(url,headers=header)
    json_str = json.loads(r.text)

    if (int(json_str['status_code']) == int('0')):
        if ("user_info_list" in json_str):
            av = json_str['user_info_list']
            for d in av:
                url = str(d['avatar'])
                if (url == "c16000003f97583dac4" or url == "b76600039bd12b4c09da"):
                    print("用户名:"+d['nickname']+" 不正常")
                    text = str('\n'+d['nickname'])
                    file.write(text)
                    sl+=1
                    yczh+=1
                else:
                    # print("用户名:"+d['nickname']+" 正常")
                    sl+=1
            sbdy = str(json_str['cursor'])
        else:
            print("检测完成,已检测账号"+str(sl)+"个,异常账号共计"+str(yczh)+"个")
            print("异常账号存储在: "+file.name)
            file.close()
            exit()
    else:
        if ("status_message" in json_str):
            print(json_str['status_message']+",已检测账号"+str(sl)+"个")
            print("等待3分钟继续执行")
            time.sleep(180)
            print("继续执行")
        else:
            print(json_str)
            print(sbdy)
            yn = input("是否重试,继续执行?[y/n]")
            if (yn == "n"):
                file.close()
                exit()