根据分享的主页链接,实现24小时监控点赞、粉丝、关注、喜欢的变化,从而系统了解她对抖音的痴迷程度
正式开始:
1、分享女生抖音主页面,在浏览器中打开个人主页链接大概长这样:https://v.douyin.com/J5n**GH/
2、短链接会自动跳转到长连接,长连接形如:https://www.iesdouyin.com/share/user/585163***20?u_code=16eel***k&sec_uid=MS4wLj*******xujYr-dU1rAP4pZPWo0esLAH8g6wWzKQcrF-Tm_E3A×tamp=1603755850&utm_source=copy&utm_campaign=client_share&utm_medium=android&share_app_name=douyin
3、复制其中的sec_uid,这就是个人标识了,据我研究每个人的sec_uid是保持不变的
4、带入程序中,剩下的具体数据统计就交给在座的各位了
核心代码如下:
[Python] 纯文本查看 复制代码 import requests
import json
import time
class Leader(object):
def __init__(self, secUid):
'''
初始化用户uid,生成request对象
'''
self.s = requests.Session()
headers = {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
}
self.s.headers.update(headers)
self.secUid = secUid
def getBaseInfo(self):
'''
获取用户信息,返回字典
'''
url = "https://www.iesdouyin.com/web/api/v2/user/info/?sec_uid={}".format(
self.secUid)
res = self.s.get(url)
return res.json().get("user_info", {"none", "none"})
def getLeaderInfo(self, infoDict):
nickName = infoDict.get("nickname", "")
totalFavorited = infoDict.get("total_favorited", "")
# 点赞
followingCount = infoDict.get("following_count", "")
# 关注
followerCount = infoDict.get("follower_count", "")
# 粉丝
favoritingCount = infoDict.get("favoriting_count", "")
# 喜欢的作品数量
shortId = infoDict.get("short_id", "")
# 可被搜索的短id
awemeCount = infoDict.get("aweme_count", "")
# 发布内容数量
LeaderInfo = {}
LeaderInfo["nickName"] = nickName
LeaderInfo["totalFavorited"] = totalFavorited
LeaderInfo["followingCount"] = followingCount
LeaderInfo["followerCount"] = followerCount
LeaderInfo["favoritingCount"] = favoritingCount
LeaderInfo["shortId"] = shortId
LeaderInfo["awemeCount"] = awemeCount
return LeaderInfo
def save(self, LeaderInfo):
# 保存抓取数据
strInfo = json.dumps(LeaderInfo, indent=4, ensure_ascii=False)
print(strInfo)
def sleep(self, delay=15):
# 睡眠时间,秒
print("{}秒之后再次抓取".format(delay))
time.sleep(delay)
if __name__ == "__main__":
secUid = "MS4wLj*******xujYr-dU1rAP4pZPWo0esLAH8g6wWzKQcrF-Tm_E3A"
for i in range(10000):
leader = Leader(secUid)
baseInfo = leader.getBaseInfo()
leaderInfo = leader.getLeaderInfo(baseInfo)
leader.save(leaderInfo)
leader.sleep()
有喜欢的给个赞吧。谢谢!
|