-
Notifications
You must be signed in to change notification settings - Fork 2
/
huitie.py
72 lines (59 loc) · 2.46 KB
/
huitie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# coding=utf-8
from bs4 import BeautifulSoup
import re
import requests
import json
import math
import time
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def str2dic(text):
idic = {}
ilist = text.split('&')
for item in ilist:
name, value = item.split('=', 1)
idic[name] = value
return idic
def reply(reply_text, tid):
huitie_data_text = 'ie=utf-8&kw=华中科技大学&fid=817&tid=4811894587&vcode_md5=&floor_num=1&rich_text=1&tbs=1234567&content=12345&files=[]&mouse_pwd=104,105,105,119,104,108,99,107,82,106,119,107,119,106,119,107,119,106,119,107,119,106,119,107,119,106,119,107,82,98,110,111,98,82,106,104,109,109,119,108,109,99,14764590727910&mouse_pwd_t=1476459072791&mouse_pwd_isclick=0&__type__=reply'
huitie_data = str2dic(huitie_data_text)
huitie_data['content'] = reply_text
huitie_data['tid'] = tid
c_cookies = {
'BDUSS': '这个地方放你的BDUSS'}
# 增加自动获取tbs,tbs必须带cookies获取,并且一段时间后会失效
url = 'http://tieba.baidu.com/dc/common/tbs'
r_tbs = requests.get(url, cookies=c_cookies)
r_tbs = json.loads(r_tbs.text)
huitie_data['tbs'] = r_tbs["tbs"]
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36',
'Referer': 'http://tieba.baidu.com/p/4811894587'}
huitie_data['mouse_pwd_t'] = str(math.floor(time.time() * 1000))
huitie_data[
'mouse_pwd'] = '2,2,12,24,5,3,2,4,61,5,24,4,24,5,24,4,24,5,24,4,24,5,24,4,24,5,24,4,61,5,13,0,12,12,4,61,5,13,6,4,24,5,4,12,4,' + \
huitie_data['mouse_pwd_t'] + '0'
res = requests.post('http://tieba.baidu.com/f/commit/post/add', data=huitie_data, headers=headers,
cookies=c_cookies)
# print(res.text)
pattern_check = re.compile('"no":(.*?),')
check_num = int(re.findall(pattern_check, res.text)[0])
# print(check_num)
if check_num == 0:
# pattern = re.compile('"content":"(.*?)",')
# content = re.findall(pattern, res.text)[0]
print('回帖成功'
# ',回复内容为:' + content
)
elif check_num == 40:
print('回帖失败,需要验证码')
else:
print('回帖失败')
print '-------------------------' \
''
'''
time.sleep(4)
reply(23456)
'''
# reply(123456, 4822257291)