python requests 简单实现易班自动登录,批量_文章发布,投票发布,评论,点赞,v2.0

小编能力有限,本文纯属瞎编,如有异议,你去打辅导员涩

一.前戏

    有个操蛋,操蛋,操蛋的辅导员促使小编成长,原因:易班需要活跃度,辅导员安排班上每个人必须去易班上 写文章,写评论,发投票...  我觉得辅导员肯定小瞧我们了,我们班像好好刷易班的人嘛。

    结果就鸡儿了涩,都没去发。直接导致辅导员强行安排(早上6.50格老子全班跑操,跑到易班活跃度足够为止!!!), 不要问我那个学校的,厂长也不是我表哥

二.话不多说,上码

 

登录易班

 

 1 person = requests.Session()
 2 cookies = person.cookies.get_dict()  # cookies
 3 # print(cookie
 4 person.headers = {
 5     "Accept": "application/json, text/javascript, */*; q=0.01",
 6     "Accept-Encoding": "gzip, deflate, br",
 7     "Accept-Language": "zh-CN,zh;q=0.9",
 8     "Connection": "keep-alive",
 9     "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
10     # "Host": "q.yiban.cn",
11     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
12                   "(KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
13 }
14 user ="你的"
15 password ="你的"
16 # 登录易班
17 def login(user, password):
18     login_page_url = "https://www.yiban.cn/login"
19     login_page_res = person.get(url=login_page_url,cookies=cookies)
20     # print(login_page_res.text)
21     # 获取公钥并加密
22     public_key = re.findall(r"BEGIN PUBLIC KEY-----\sM(.*)-----END PUBLIC KEY", login_page_res.text, re.S)[0]
23     public_key = '-----BEGIN PUBLIC KEY-----\nM' + public_key + '-----END PUBLIC KEY-----'
24     rsa_key = RSA.importKey(public_key)
25     x = rsa.encrypt(password.encode(), rsa_key)
26     rsa_pass = base64.b64encode(x).decode()
27     # 获取时间戳
28     keys_time = re.findall(r"data-keys-time='(.*?)'", login_page_res.text)[0]
29     check_in = captcha()
30     # random = time.time()
31     # random = round(random, 2)  # 只取两位小数
32 
33     # 登录易班
34     login_url = "https://www.yiban.cn/login/doLoginAjax"
35     login_data = {
36         "account": user,
37         "password": rsa_pass,
38         "captcha": check_in,
39         "keysTime": keys_time
40     }
41 
42     login_res = person.post(url=login_url, data=login_data, cookies=cookies)
43     # print(login_res.json())
44     # 获取登录结果
45     getlogin_url = "http://www.yiban.cn/ajax/my/getLogin"
46     getlogin_data = {
47         "": ""
48     }
49     getlogin_res = person.post(url=getlogin_url, data=getlogin_data)
50     print(getlogin_res)
51     getlogin_res_content = getlogin_res.json()
52     print(getlogin_res_content)
53     # messages = person.post(url='http://www.yiban.cn/forum/article/listAjax',data=login_data)
54     # print(messages.text)
55 
56 
57 # 验证码
58 def captcha():  # 图片验证码
59     captcha_check_url = "https://www.yiban.cn/captcha/index?Tue%20Dec%2004%202018%2000:01:2" \
60                         "6%20GMT+0800%20(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)"
61     captcha_check_respond = person.get(url=captcha_check_url)
62     print(captcha_check_respond)
63     captcha_content = captcha_check_respond.content  # 转换类型
64     fb = open('captcha.jpg', 'wb')  # 把字节类型转换为图片文件
65     fb.write(captcha_content)
66     fb.close()
67     check_in = input("请输入图片验证码>>>:")
68     return check_in

  

 

 

批量文章发布,投票发布,点赞,评论

注:使用了多线程,优点:速度更快,缺点:容易封号,慎重使用

  

  1 Author:jum
  2 from yibanban.common.common import *
  3 
  4 
  5 def get_article_id():  # 获取文章id
  6     json_data_list = {
  7         "channel_id": 自己的,
  8         "puid": 自己的,
  9         "page": 1,
 10         "size": 10,
 11         "orderby": "updateTime",
 12         "Sections_id": -1,
 13         "need_notice": 0,
 14         "group_id": 自己的,
 15         "my": 0,
 16         "lastId": 自己的
 17     }
 18     res = person.post(url="http://www.yiban.cn/forum/article/listAjax", data=json_data_list)
 19     # 获取json数据
 20     json_list0 = res.json()
 21     # 数据筛选
 22 
 23     # article_list = re.findall("id(.*?)Channel_id", str(json_list0))
 24     article_list = jsonpath.jsonpath(json_list0, '$..id')
 25     article_list1 = re.findall("([56789][0-9]{7})", str(article_list))
 26     # for i in article_list:
 27     #     n = re.findall("\d+",i)
 28     #     for m in n:
 29     #         article_list1.append(m)
 30     # jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
 31     print(json_list0)
 32     print(type(article_list))
 33     print(article_list)
 34     print(article_list1)
 35     return article_list1
 36 
 37 
 38 # 文章点赞
 39 def good():  # 点赞
 40     article_id = change_page()
 41     for i in article_id:
 42         print(i)
 43         article_data = {
 44             "article_id": i,
 45             "channel_id": 自己的,
 46             "puid": 自己的
 47         }
 48         good_res = person.post(url="http://www.yiban.cn/forum/article/upArticleAjax", data=article_data, headers={
 49             'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
 50             'Accept': 'application/json, text/javascript, */*; q=0.01',
 51             'Accept-Language': 'zh-CN,zh;q=0.9',
 52         })
 53         print(good_res)
 54 
 55 
 56 # 文章评论
 57 def comment():  # 评论
 58     article_id = change_page()
 59     for i in article_id:
 60         print(i)
 61         article_data = {
 62             "channel_id": 自己的,
 63             "puid": 自己的,
 64             "article_id": i,
 65             "content": "弟子规",
 66             "reply_id": 0,
 67             "syncFeed": 1,
 68             "isAnonymous": 0
 69         }
 70         good_res = person.post(url="http://www.yiban.cn/forum/reply/addAjax", data=article_data,
 71                                headers={
 72                                    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
 73                                    'Accept': 'application/json, text/javascript, */*; q=0.01',
 74                                    'Accept-Language': 'zh-CN,zh;q=0.9',
 75                                })
 76         print(good_res)
 77 
 78 
 79 # 翻页
 80 def change_page():  # 翻页
 81     num_page = 1
 82     article_list2 = []
 83     for num in range(10):
 84         json_data_list = {
 85             "channel_id": 281421,
 86             "puid": 7245623,
 87             "page": num_page,
 88             "size": 10,
 89             "orderby": "hotScore",
 90             "Sections_id": -1,
 91             "need_notice": 0,
 92             "group_id": 457740,
 93             "my": 0
 94         }
 95         num_page += 1
 96         res = person.post(url="http://www.yiban.cn/forum/article/listAjax", data=json_data_list)
 97         # 获取json数据
 98         json_list0 = res.json()
 99         # 数据筛选
100         # article_list = re.findall(".*id(.*)Channel_id.*", json_list0)
101         article_list = jsonpath.jsonpath(json_list0, '$..id')
102         # jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
103         print(json_list0)
104         article_list1 = re.findall("([56789][0-9]{7})", str(article_list))
105         for a in article_list1:
106             article_list2.append(a)
107         # jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
108         print(json_list0)
109         print(type(article_list))
110         print(article_list)
111         print(article_list1)
112     print(article_list2)
113     return article_list2
114 
115 
116 # 添加文章
117 def article_add():
118     article_data = {
119         "puid": 自己的,
120         "pubArea": 自己的,
121         "title": "test",
122         "content": "<p>this is robot auto article!!!!!</p>",
123         "isNotice": "false",
124         "dom": ".js-submit"
125     }
126     article_data_res = person.post(url="http://www.yiban.cn/forum/article/addAjax", data=article_data, headers={
127         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
128         'Accept': 'application/json, text/javascript, */*; q=0.01',
129         'Accept-Language': 'zh-CN,zh;q=0.9',
130     }
131                                    )
132     print(article_data_res.json())
133 
134 
135 # 添加投票
136 def vote_add():  # 投票
137     vote_data = {
138         "puid": 自己的,
139         "scope_ids": 自己的,
140         "title": "换个姿势再来一次",
141         "subjectTxt": None,
142         "subjectPic": None,
143         "options_num": 3,
144         "scopeMin": 1,
145         "scopeMax": 1,
146         "minimum": 1,
147         "voteValue": "2019-07-21 13:15",
148         "voteKey": 2,
149         "public_type": 0,
150         "isAnonymous": 1,
151         "voteIsCaptcha": 0,
152         "istop": 1,
153         "sysnotice": 2,
154         "isshare": 1,
155         "rsa": 1,
156         "dom": " .js-submit",
157         "group_id": 自己的,
158         "subjectTxt_1": "vote1--",
159         "subjectTxt_2": "vote2",
160         "subjectTxt_3": "vote3"
161     }
162     vote_data_res = person.post(url="http://www.yiban.cn/vote/vote/add", data=vote_data, headers={
163         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
164         'Accept': 'application/json, text/javascript, */*; q=0.01',
165         'Accept-Language': 'zh-CN,zh;q=0.9', })
166     print(vote_data_res.json())
167 
168 
169 # http://www.yiban.cn/Newgroup/showMorePub/group_id/457740/puid/7245623/type/3/page/1
170 # 初始化投票,评论
171 def get_vote_url():
172     for i in range(50):
173         start_url = "http://www.yiban.cn/Newgroup/showMorePub/group_id/457740/puid/7245623/type/3/page/{0}".format(i)
174         resp = person.get(url=start_url)
175         response = Selector(resp)
176         url_list = response.css(' .vote-itd2 a::attr(href)').extract()
177         next_url = response.css('.pager .next::attr(href)').extract()
178         print(next_url)  # 下一页url
179         print(url_list)  # 整页投票url
180         for i in url_list:
181             vote_id = re.findall("vote_id/(.*?)/puid", i)
182             author_id = re.findall("actor_id/(.*?)/status", i)
183             # print(author_id)
184             # print(vote_id)
185             # print(type(vote_id))
186             # vote_url = "http://www.yiban.cn{0}".format(i)
187             # "pagetype": 2,  (1代表未过期,2代表已过期)
188             # 提取网页过期时间, 与当前时间做对比
189             # vote / vote / showDetail / vote_id / 54280789 / puid / 7245623 / group_id / 457740 / actor_id / 12806206 / status / 1
190             vate_data = {
191                 "vote_id": vote_id[0],
192                 "uid": 自己的,
193                 "puid": 自己的,
194                 "pagetype": 1,
195                 "group_id": 自己的,
196                 "actor_id": 自己的,
197                 "top_power": "f",
198                 "edit_power": "f",
199                 "end_power": "f",
200                 "del_power": "f",
201                 "block_power": "f",
202                 "isSchoolVerify": 1,
203                 "is_public": "f",
204                 "is_anonymous": "t",
205                 "token": "",
206                 "out_power": "f",
207                 "isMember": "",
208                 "url%5BgetVoteDetail%5D": "vote%2Fvote%2FgetVoteDetail",
209                 "url%5Boutput%5D": "%2Fvote%2FExpand%2Foutput",
210                 "rl%5BgetCommentDetail%5D": "vote%2Fvote%2FgetCommentDetail",
211                 "url%5BaddComment%5D": "vote%2Fvote%2FaddComment",
212                 "url%5BeditLove%5D": "vote%2Fvote%2FeditLove",
213                 "url%5Bvote%5D": "vote%2Fvote%2Fact",
214                 "url%5BsetIsTop%5D": "vote%2FExpand%2FsetIsTop",
215                 "url%5BsetManualEndVote%5D": "vote%2FExpand%2FsetManualEndVote",
216                 "url%5BdelVote%5D": "vote%2FExpand%2FdelVote",
217                 "url%5BdelComment%5D": "vote%2Fvote%2FdelComment",
218                 "url%5BshieldVote%5D": "vote%2FExpand%2FshieldVote",
219                 "url%5BgetAnonymous%5D": "vote%2FExpand%2FgetAnonymous",
220                 "url%5BuserInfo%5D": "user%2Findex%2Findex",
221                 "isLogin": 1,
222                 "isOrganization": 0,
223                 "ispublic": 0,
224             }
225             vote_res = person.post(url="http://www.yiban.cn/vote/vote/getVoteDetail", data=vate_data, cookies=cookies,
226                                    headers={
227                                        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
228                                        'Accept': 'application/json, text/javascript, */*; q=0.01',
229                                        'Accept-Language': 'zh-CN,zh;q=0.9'})
230             response_f = vote_res.json()
231             # print(response_f)
232             # print(type(response_f))
233             dict1 = response_f['data']
234             dict_l = dict1['vote_list']
235             dict_t = dict1['option_list']
236             # print(dict_t)
237 
238             # 选取全部voptions_id 投票选项id
239             v_list = []
240             for i in dict_t:
241                 v_list.append(dict(i)["id"])
242             print(v_list)
243 
244             # 提取是否已投票
245             v_list1 = []
246             for m in dict_t:
247                 try:
248                     v_list1.append(dict(m)["is_vote"])
249                 except KeyError:
250                     pass
251             print(v_list1)
252 
253             # min
254             minimum = int(dict_l['minimum'])  # 投票数 单选or多选
255             scopeMax = int(dict_l['scopeMax'])
256 
257             # mount_id
258             mount_id = int(dict_l['mount_id'])  # 投票数 单选or多选
259 
260             # end_time
261             end_time = dict_l['voteValue'] + ":00"  # 结束时间
262 
263             # 时间转时间戳
264             timeArray = time.strptime(end_time, "%Y-%m-%d %H:%M:%S")  # 时间数组
265             timeStamp = int(time.mktime(timeArray))  # 时间戳
266             print(timeStamp)
267             if cmp_time(int(timeStamp)) == 1 and len(v_list1) == 0:  # 判断是否过期或已投票
268                 voptions_id = voptions_id_chiose(minimum, v_list)
269                 vate_choise(vote_id[0], author_id[0], minimum, scopeMax, voptions_id)  # 投票
270                 vate_comment(vote_id, author_id, mount_id)  # 评论
271             else:
272                 vate_comment(vote_id, author_id, mount_id)
273 
274 
275 # def vote_chenge(next_url):
276 #     if next_url:
277 #         next_url ="{0}next_url".format("www.yiban.cn/")
278 #     else:
279 #         brack
280 #     ret
281 
282 
283 # 判断多选or单选
284 def voptions_id_chiose(minimum, v_list):
285     import random
286     if minimum == 1:
287         voptions_id = []
288         i = random.randint(0, minimum)
289         voptions_id.append(v_list[i])
290         voptions_id1 = [str(i) for i in voptions_id]  # 遍历各元素使之成为字符元素
291         str_voptions_id = "".join(voptions_id1)
292         # 单选
293     else:
294         n = len(v_list)
295         m = random.sample(range(0, n), minimum)
296         voptions_id = []
297         for i in m:
298             voptions_id.append(v_list[i])
299         print(voptions_id)
300         voptions_id1 = [str(i) for i in voptions_id]  # # 遍历各元素使之成为字符元素
301         str_voptions_id = ",".join(voptions_id1)
302         # 多选
303     return str_voptions_id
304 
305 
306 # 判断投票是否过期
307 def cmp_time(end_time):
308     n_time = time.time()
309     pagetype = 1
310     if int(n_time) > end_time:
311         pagetype = 2
312     return pagetype
313 
314 
315 # 选择投票
316 def vate_choise(vote_id, author_id, minimum, scopeMax, voptions_id):
317     vate_data = {
318         "puid": 自己的,
319         "group_id": 自己的,
320         "vote_id": vote_id,
321         "actor_id": author_id,
322         "voptions_id": voptions_id,
323         "minimum": minimum,
324         "scopeMax": scopeMax,
325     }
326     res = person.post(url="http://www.yiban.cn/vote/vote/act", data=vate_data, cookies=cookies,
327                       headers={
328                           'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
329                           'Accept': 'application/json, text/javascript, */*; q=0.01',
330                           'Accept-Language': 'zh-CN,zh;q=0.9'})
331     print(res.json())
332 
333 
334 # 投票评论
335 def vate_comment(vote_id, author_id, mount_id):
336     comment_data = {
337         "mountid": mount_id,
338         "msg": "换个姿势再来一次",
339         "group_id": 自己的,
340         "actor_id": 自己的,
341         "vote_id": vote_id,
342         "author_id": author_id,
343         "puid": 自己的,
344         "reply_comment_id": 0,
345         "reply_user_id": 0,
346     }
347     res = person.post(url="http://www.yiban.cn/vote/vote/addComment", data=comment_data, cookies=cookies,
348                       headers={
349                           'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
350                           'Accept': 'application/json, text/javascript, */*; q=0.01',
351                           'Accept-Language': 'zh-CN,zh;q=0.9'})
352     print(res.json())
353 
354 
355 # http://www.yiban.cn/vote/vote/getVoteDetail
356 import threading
357 if __name__ == '__main__':
358     login(user, password)
359     [vote_add() for i in range(20)]
360     for _ in range(30):
361         # t1 = threading.Thread(target=vote_add)
362         # t2 = threading.Thread(target=article_add)
363         t3 = threading.Thread(target=get_vote_url)
364         # t1.start()
365         # t2.start()
366         t3.start()

 

 

 

-------------------------------------------------注解 注解 注解--------------------------------------------------

注:易班post提交数据{
     "account": user,
"password": rsa_pass, 加密了  rsa加密 审查源码发现公钥在源码内,pycryptodemo按照易班的方式加密在提交(之请搞得我头痛,参照http://www.cnblogs.com/RealMaang/articles/10071602.html
"captcha": check_in, 验证码  这个没得办法,只有下载到本地人工读取(貌似google有一款图片识别,但是效率低)
"keysTime": keys_time 时间戳 差毫秒就会登录超时(提取网页内的时间戳完美,用time.time()我试了好多次都不行)
}
暂时文章投票只能发二十条,然后就是验真码了,我试了time.sleep(1) 显然易班不是这个机制
未完待续...
邮箱:bigmaxgod@qq.com
转载注明出处:https://www.cnblogs.com/jum-bolg/p/10792853.html

posted @ 2019-04-29 21:01  jum_blog  阅读(2785)  评论(2编辑  收藏  举报

载入天数...载入时分秒...