因为最近有需要统计易瞄瞄指定话题下的用户发表的动态内容,还需要统计点赞数,发表时间等信息,因此随手写了一个小脚本,这个呢就不写教程了,直接放代码和效果图,需要自己手动获取易班的login_token,抓客户端包即可,或者浏览器F12,以前也写过易班登录JS。修改topicid既可切换话题
import re import time import requests print('正在获取秘钥!') info = input("请输入Token") url = f'https://ymm.yiban.cn/news/list/news?loginToken={info}&page=1&size=100&topicId=2' res = requests.get(url=url).json() if res['message'] == "操作成功" and info['version'] == "暂无": data = res['data']['list'] print('正在下载数据!') with open('易喵喵点赞数量.csv', 'w', encoding='utf8') as f: f.write('用户id,学号,用户名,文字内容,11点,赞数,发布时间 ') print("正在写入数据!") for i in data: title = i['title'].replace(' ', '').replace(',', ',') likenum = i['likeNum'] time_local = time.localtime(int(i['createTime'])) date = time.strftime("%Y-%m-%d %H:%M:%S", time_local) riqi = time.strftime('%H', time_local) if int(riqi) > 11: riqi = "11点前" else: riqi = "11点后" xuehao = re.findall('([2][0][1][1-9]d*)', title) if xuehao: xuehao = xuehao[0] userid = i['origin']['User_id'] usernick = i['origin']['usernick'].replace(',', ',') f.write(f'{userid},{xuehao},{usernick},{title},{riqi},{likenum},{date} ') print(f'{userid},{xuehao},{usernick},{title},{riqi},{likenum},{date}') print("作者:Lan,www.lanol.cn") input("结果已生成在软件目录下") else: input("获取失败,请联系Lan")
评论 (0)