#! python3
# -*- coding:utf-8 -*-
import requests
import re
import hashlib
import json
import time
class tieba:
# 填入自己的cookie中的bduss
bduss = ''
# 填入自己的百度id
myid = ''
url = 'http://tieba.baidu.com/home/main?un=' + myid + '&fr=index'
headers = {'Cookie': 'BDUSS=' + bduss}
lists = []
def __init__(self):
self.get_list()
def chlis(self, kw):
for i in range(len(self.lists)):
if self.lists[i]['name'] == kw:
self.lists[i]['is_sign'] = 1
def get_list(self):
r = requests.get(self.url, headers=self.headers)
rul = re.findall(r'forumArr":(\[.+?), "ihome"', r.text)[0]
ruls = re.findall(r'{.+?}', rul)
for i in ruls:
one = eval(i)
self.lists.append(
{'name': one['forum_name'], 'is_sign': one['is_sign']})
def getPostDita(self, kws):
tbs = requests.get('http://tieba.baidu.com/dc/common/tbs',
headers=self.headers).json()['tbs']
get_fid_url = 'http://tieba.baidu.com/f/commit/share/fnameShareApi?ie=utf-8&fname=%s' % kws
fid = requests.get(get_fid_url, headers=self.headers).json()[
'data']['fid']
return {'fid': fid, 'kw': kws, 'BDUSS': self.bduss, 'tbs': tbs}
def getData(self, postDict):
p_sign = "BDUSS={BDUSS}fid={fid}kw={kw}tbs={tbs}tiebaclient!!!"
postDict['sign'] = hashlib.md5(p_sign.format(
**postDict).encode('utf-8')).hexdigest().upper()
return postDict
def sign(self, kw):
postDict = self.getPostDita(kw)
postData = self.getData(postDict)
r = requests.post(
'http://c.tieba.baidu.com/c/c/forum/sign', data=postData)
info = r.json()
if info['error_code'] == '0':
self.chlis(kw)
print('Success:%s' % kw)
return 0
else:
print('Fail:%s' % kw)
return 1
def main():
tb = tieba()
flag = 1
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))
print('********************')
while flag:
flag = sum([tb.sign(k['name']) for k in tb.lists if not k['is_sign']])
print('********************\nAll Finished!\n\n')
if __name__ == '__main__':
main()
童小纯
- 粉丝: 3w+
- 资源: 289
最新资源
- MATLAB(GUI)交通标志识别[语音播报,GUI界面,解析].zip
- MATLAB(GUI)交通标志系统(多种标志,语音播报,Bp神经网络).zip
- MATLAB(GUI)家居防火(火焰识别的创新应用,有火焰则发送信息给模拟用户终端).zip
- MATLAB(GUI)教室人数统计(GUI框架,定位和分割人脸,计数).zip
- MATLAB(GUI)交通道路标识识别[红蓝黄,Bp算法].zip
- MATLAB(GUI)金属表面缺陷分析(SVM算法).zip
- MATLAB(GUI)考勤系统(Cnn卷积神经网络,GUI框架).zip
- MATLAB(GUI)口罩识别[未戴预警,GUI界面框架].zip
- MATLAB(GUI)口罩检测(不同类型口罩,GUI界面).zip
- MATLAB(GUI)口罩识别[自动定位颜色,多人检测,未戴预警 ].zip
- MATLAB(GUI)垃圾分类系统(同时识别多类,边缘和颜色的方法,Bp神经网络方法).zip
- MATLAB(GUI)口罩识别检测[自动定位颜色,未戴口罩预警,语音播报].zip
- Screenshot_2025-01-08-14-14-20-093_com.tencent.mm.jpg
- MATLAB(GUI)垃圾识别(GUI界面,自动定位垃圾).zip
- MATLAB(GUI)疲劳专注度检测系统(GUI框架,图片可换).zip
- MATLAB(GUI)疲劳检测GUI设计(可更换图片 ).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈