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

一.前戏

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

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

二.话不多说,上码

 

登录易班

 person = requests.Session()
cookies = person.cookies.get_dict() # cookies
# print(cookie
person.headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection": "keep-alive",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
# "Host": "q.yiban.cn",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
}
user ="你的"
password ="你的"
# 登录易班
def login(user, password):
login_page_url = "https://www.yiban.cn/login"
login_page_res = person.get(url=login_page_url,cookies=cookies)
# print(login_page_res.text)
# 获取公钥并加密
public_key = re.findall(r"BEGIN PUBLIC KEY-----\sM(.*)-----END PUBLIC KEY", login_page_res.text, re.S)[0]
public_key = '-----BEGIN PUBLIC KEY-----\nM' + public_key + '-----END PUBLIC KEY-----'
rsa_key = RSA.importKey(public_key)
x = rsa.encrypt(password.encode(), rsa_key)
rsa_pass = base64.b64encode(x).decode()
# 获取时间戳
keys_time = re.findall(r"data-keys-time='(.*?)'", login_page_res.text)[0]
check_in = captcha()
# random = time.time()
# random = round(random, 2) # 只取两位小数 # 登录易班
login_url = "https://www.yiban.cn/login/doLoginAjax"
login_data = {
"account": user,
"password": rsa_pass,
"captcha": check_in,
"keysTime": keys_time
} login_res = person.post(url=login_url, data=login_data, cookies=cookies)
# print(login_res.json())
# 获取登录结果
getlogin_url = "http://www.yiban.cn/ajax/my/getLogin"
getlogin_data = {
"": ""
}
getlogin_res = person.post(url=getlogin_url, data=getlogin_data)
print(getlogin_res)
getlogin_res_content = getlogin_res.json()
print(getlogin_res_content)
# messages = person.post(url='http://www.yiban.cn/forum/article/listAjax',data=login_data)
# print(messages.text) # 验证码
def captcha(): # 图片验证码
captcha_check_url = "https://www.yiban.cn/captcha/index?Tue%20Dec%2004%202018%2000:01:2" \
"6%20GMT+0800%20(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)"
captcha_check_respond = person.get(url=captcha_check_url)
print(captcha_check_respond)
captcha_content = captcha_check_respond.content # 转换类型
fb = open('captcha.jpg', 'wb') # 把字节类型转换为图片文件
fb.write(captcha_content)
fb.close()
check_in = input("请输入图片验证码>>>:")
return check_in

  

 

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

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

  

 Author:jum
from yibanban.common.common import * def get_article_id(): # 获取文章id
json_data_list = {
"channel_id": 自己的,
"puid": 自己的,
"page": 1,
"size": 10,
"orderby": "updateTime",
"Sections_id": -1,
"need_notice": 0,
"group_id": 自己的,
"my": 0,
"lastId": 自己的
}
res = person.post(url="http://www.yiban.cn/forum/article/listAjax", data=json_data_list)
# 获取json数据
json_list0 = res.json()
# 数据筛选 # article_list = re.findall("id(.*?)Channel_id", str(json_list0))
article_list = jsonpath.jsonpath(json_list0, '$..id')
article_list1 = re.findall("([56789][0-9]{7})", str(article_list))
# for i in article_list:
# n = re.findall("\d+",i)
# for m in n:
# article_list1.append(m)
# jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
print(json_list0)
print(type(article_list))
print(article_list)
print(article_list1)
return article_list1 # 文章点赞
def good(): # 点赞
article_id = change_page()
for i in article_id:
print(i)
article_data = {
"article_id": i,
"channel_id": 自己的,
"puid": 自己的
}
good_res = person.post(url="http://www.yiban.cn/forum/article/upArticleAjax", data=article_data, headers={
'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',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9',
})
print(good_res) # 文章评论
def comment(): # 评论
article_id = change_page()
for i in article_id:
print(i)
article_data = {
"channel_id": 自己的,
"puid": 自己的,
"article_id": i,
"content": "弟子规",
"reply_id": 0,
"syncFeed": 1,
"isAnonymous": 0
}
good_res = person.post(url="http://www.yiban.cn/forum/reply/addAjax", data=article_data,
headers={
'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',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9',
})
print(good_res) # 翻页
def change_page(): # 翻页
num_page = 1
article_list2 = []
for num in range(10):
json_data_list = {
"channel_id": 281421,
"puid": 7245623,
"page": num_page,
"size": 10,
"orderby": "hotScore",
"Sections_id": -1,
"need_notice": 0,
"group_id": 457740,
"my": 0
}
num_page += 1
res = person.post(url="http://www.yiban.cn/forum/article/listAjax", data=json_data_list)
# 获取json数据
json_list0 = res.json()
# 数据筛选
# article_list = re.findall(".*id(.*)Channel_id.*", json_list0)
article_list = jsonpath.jsonpath(json_list0, '$..id')
# jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
print(json_list0)
article_list1 = re.findall("([56789][0-9]{7})", str(article_list))
for a in article_list1:
article_list2.append(a)
# jsonpath文档https://www.cnblogs.com/aoyihuashao/p/8665873.html
print(json_list0)
print(type(article_list))
print(article_list)
print(article_list1)
print(article_list2)
return article_list2 # 添加文章
def article_add():
article_data = {
"puid": 自己的,
"pubArea": 自己的,
"title": "test",
"content": "<p>this is robot auto article!!!!!</p>",
"isNotice": "false",
"dom": ".js-submit"
}
article_data_res = person.post(url="http://www.yiban.cn/forum/article/addAjax", data=article_data, headers={
'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',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
)
print(article_data_res.json()) # 添加投票
def vote_add(): # 投票
vote_data = {
"puid": 自己的,
"scope_ids": 自己的,
"title": "换个姿势再来一次",
"subjectTxt": None,
"subjectPic": None,
"options_num": 3,
"scopeMin": 1,
"scopeMax": 1,
"minimum": 1,
"voteValue": "2019-07-21 13:15",
"voteKey": 2,
"public_type": 0,
"isAnonymous": 1,
"voteIsCaptcha": 0,
"istop": 1,
"sysnotice": 2,
"isshare": 1,
"rsa": 1,
"dom": " .js-submit",
"group_id": 自己的,
"subjectTxt_1": "vote1--",
"subjectTxt_2": "vote2",
"subjectTxt_3": "vote3"
}
vote_data_res = person.post(url="http://www.yiban.cn/vote/vote/add", data=vote_data, headers={
'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',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9', })
print(vote_data_res.json()) # http://www.yiban.cn/Newgroup/showMorePub/group_id/457740/puid/7245623/type/3/page/1
# 初始化投票,评论
def get_vote_url():
for i in range(50):
start_url = "http://www.yiban.cn/Newgroup/showMorePub/group_id/457740/puid/7245623/type/3/page/{0}".format(i)
resp = person.get(url=start_url)
response = Selector(resp)
url_list = response.css(' .vote-itd2 a::attr(href)').extract()
next_url = response.css('.pager .next::attr(href)').extract()
print(next_url) # 下一页url
print(url_list) # 整页投票url
for i in url_list:
vote_id = re.findall("vote_id/(.*?)/puid", i)
author_id = re.findall("actor_id/(.*?)/status", i)
# print(author_id)
# print(vote_id)
# print(type(vote_id))
# vote_url = "http://www.yiban.cn{0}".format(i)
# "pagetype": 2, (1代表未过期,2代表已过期)
# 提取网页过期时间, 与当前时间做对比
# vote / vote / showDetail / vote_id / 54280789 / puid / 7245623 / group_id / 457740 / actor_id / 12806206 / status / 1
vate_data = {
"vote_id": vote_id[0],
"uid": 自己的,
"puid": 自己的,
"pagetype": 1,
"group_id": 自己的,
"actor_id": 自己的,
"top_power": "f",
"edit_power": "f",
"end_power": "f",
"del_power": "f",
"block_power": "f",
"isSchoolVerify": 1,
"is_public": "f",
"is_anonymous": "t",
"token": "",
"out_power": "f",
"isMember": "",
"url%5BgetVoteDetail%5D": "vote%2Fvote%2FgetVoteDetail",
"url%5Boutput%5D": "%2Fvote%2FExpand%2Foutput",
"rl%5BgetCommentDetail%5D": "vote%2Fvote%2FgetCommentDetail",
"url%5BaddComment%5D": "vote%2Fvote%2FaddComment",
"url%5BeditLove%5D": "vote%2Fvote%2FeditLove",
"url%5Bvote%5D": "vote%2Fvote%2Fact",
"url%5BsetIsTop%5D": "vote%2FExpand%2FsetIsTop",
"url%5BsetManualEndVote%5D": "vote%2FExpand%2FsetManualEndVote",
"url%5BdelVote%5D": "vote%2FExpand%2FdelVote",
"url%5BdelComment%5D": "vote%2Fvote%2FdelComment",
"url%5BshieldVote%5D": "vote%2FExpand%2FshieldVote",
"url%5BgetAnonymous%5D": "vote%2FExpand%2FgetAnonymous",
"url%5BuserInfo%5D": "user%2Findex%2Findex",
"isLogin": 1,
"isOrganization": 0,
"ispublic": 0,
}
vote_res = person.post(url="http://www.yiban.cn/vote/vote/getVoteDetail", data=vate_data, cookies=cookies,
headers={
'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',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9'})
response_f = vote_res.json()
# print(response_f)
# print(type(response_f))
dict1 = response_f['data']
dict_l = dict1['vote_list']
dict_t = dict1['option_list']
# print(dict_t) # 选取全部voptions_id 投票选项id
v_list = []
for i in dict_t:
v_list.append(dict(i)["id"])
print(v_list) # 提取是否已投票
v_list1 = []
for m in dict_t:
try:
v_list1.append(dict(m)["is_vote"])
except KeyError:
pass
print(v_list1) # min
minimum = int(dict_l['minimum']) # 投票数 单选or多选
scopeMax = int(dict_l['scopeMax']) # mount_id
mount_id = int(dict_l['mount_id']) # 投票数 单选or多选 # end_time
end_time = dict_l['voteValue'] + ":00" # 结束时间 # 时间转时间戳
timeArray = time.strptime(end_time, "%Y-%m-%d %H:%M:%S") # 时间数组
timeStamp = int(time.mktime(timeArray)) # 时间戳
print(timeStamp)
if cmp_time(int(timeStamp)) == 1 and len(v_list1) == 0: # 判断是否过期或已投票
voptions_id = voptions_id_chiose(minimum, v_list)
vate_choise(vote_id[0], author_id[0], minimum, scopeMax, voptions_id) # 投票
vate_comment(vote_id, author_id, mount_id) # 评论
else:
vate_comment(vote_id, author_id, mount_id) # def vote_chenge(next_url):
# if next_url:
# next_url ="{0}next_url".format("www.yiban.cn/")
# else:
# brack
# ret # 判断多选or单选
def voptions_id_chiose(minimum, v_list):
import random
if minimum == 1:
voptions_id = []
i = random.randint(0, minimum)
voptions_id.append(v_list[i])
voptions_id1 = [str(i) for i in voptions_id] # 遍历各元素使之成为字符元素
str_voptions_id = "".join(voptions_id1)
# 单选
else:
n = len(v_list)
m = random.sample(range(0, n), minimum)
voptions_id = []
for i in m:
voptions_id.append(v_list[i])
print(voptions_id)
voptions_id1 = [str(i) for i in voptions_id] # # 遍历各元素使之成为字符元素
str_voptions_id = ",".join(voptions_id1)
# 多选
return str_voptions_id # 判断投票是否过期
def cmp_time(end_time):
n_time = time.time()
pagetype = 1
if int(n_time) > end_time:
pagetype = 2
return pagetype # 选择投票
def vate_choise(vote_id, author_id, minimum, scopeMax, voptions_id):
vate_data = {
"puid": 自己的,
"group_id": 自己的,
"vote_id": vote_id,
"actor_id": author_id,
"voptions_id": voptions_id,
"minimum": minimum,
"scopeMax": scopeMax,
}
res = person.post(url="http://www.yiban.cn/vote/vote/act", data=vate_data, cookies=cookies,
headers={
'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',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9'})
print(res.json()) # 投票评论
def vate_comment(vote_id, author_id, mount_id):
comment_data = {
"mountid": mount_id,
"msg": "换个姿势再来一次",
"group_id": 自己的,
"actor_id": 自己的,
"vote_id": vote_id,
"author_id": author_id,
"puid": 自己的,
"reply_comment_id": 0,
"reply_user_id": 0,
}
res = person.post(url="http://www.yiban.cn/vote/vote/addComment", data=comment_data, cookies=cookies,
headers={
'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',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9'})
print(res.json()) # http://www.yiban.cn/vote/vote/getVoteDetail
import threading
if __name__ == '__main__':
login(user, password)
[vote_add() for i in range(20)]
for _ in range(30):
# t1 = threading.Thread(target=vote_add)
# t2 = threading.Thread(target=article_add)
t3 = threading.Thread(target=get_vote_url)
# t1.start()
# t2.start()
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
												

python requests 简单实现易班登录,自动点赞,评论,发表的更多相关文章

  1. 一种让运行在CentOS下的.NET CORE的Web项目简单方便易部署的自动更新方案

    一.项目运行环境 项目采用的是.NET5开发的Web系统,独立部署在省内异地多台CentOS服务器上,它们运行在甲方专网环境中(不接触互联网),甲方进行业务运作时(一段时间内)会要求异地服务器开机上线 ...

  2. java 实现类似于python requests包的Session类,自动管理cookie。

    1.在py中requests.post()和get()函数都是在那个函数内部里面自动生成了一个Session类的实例,所以requests,post和get函数要想干登陆后才能干的事情,需要添加coo ...

  3. python requests简单接口自动化

    get方法 url:显而易见,就是接口的地址url啦 headers:定制请求头(headers),例如:content-type = application/x-www-form-urlencode ...

  4. python requests实现windows身份验证登录

    1.安装ntlm  https://github.com/requests/requests-ntlm pip install requests_ntlm 2.使用 import requests f ...

  5. python+requests 请求响应文本出错返回“登录超时”

    Python+requests请求响应:"msg":"登录过时" 1.出错原代码: import requests import json#页面按条件搜索返回相 ...

  6. Python:requests库、BeautifulSoup4库的基本使用(实现简单的网络爬虫)

    Python:requests库.BeautifulSoup4库的基本使用(实现简单的网络爬虫) 一.requests库的基本使用 requests是python语言编写的简单易用的HTTP库,使用起 ...

  7. Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据

    Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...

  8. Python requests模拟登录

    Python requests模拟登录 #!/usr/bin/env python # encoding: UTF-8 import json import requests # 跟urllib,ur ...

  9. 一个简单、易用的Python命令行(terminal)进度条库

    eprogress 是一个简单.易用的基于Python3的命令行(terminal)进度条库,可以自由选择使用单行显示.多行显示进度条或转圈加载方式,也可以混合使用. 示例 单行进度条 多行进度条 圆 ...

随机推荐

  1. Oracle问题之ORA-12560TNS:协议适配器错误-转载

    作者:@haimishasha本文为作者原创,转载请注明出处:https://www.cnblogs.com/haimishasha/p/5394963.html 目录 Oracle问题之ORA-12 ...

  2. Java 支付宝支付,退款,单笔转账到支付宝账户(支付宝订单退款)

    上一篇写到支付宝的支付,这代码copy下来就能直接用了,   我写学习文档时会经常贴 官方参数文档的案例地址, 因为我觉得 请求参数,响应参数说明 官方文档整理的很好,毕竟官方不会误导大家. 我学一个 ...

  3. RocketMQ 概述

    Rocket 火箭 MQ的作用:同步转异步(异步解耦). 难点:如何确保消息一定被消费,而且仅消费一次. 1.消息架构:生产者.服务器.消费者.路由发现. 2.消息顺序:严格按照消息到达服务器的顺序进 ...

  4. apache伪静态原理图

  5. 排序算法(1)--Insert Sorting--插入排序[1]--straight insertion sort--直接插入排序

    作者QQ:1095737364    QQ群:123300273     欢迎加入! 1.基本思想 将一个记录插入到已排序好的有序表中,从而得到一个新,记录数增1的有序表.即:先将序列的第1个记录看成 ...

  6. form表单提交注意事项

    1.在一个form表单中,若只有一个input(不管type是什么),按回车键表单会自动提交,但是当表单中存在多个input时,按回车键不会执行任何操作,这是form表单的一个特性. 2.在一个表单中 ...

  7. 【读书笔记】iOS-网络-底层网络

    在iOS上,有一个库叫做Core Foundation networking或CFNetwork,它是对原始Socket的轻量级封装,不过它很快对于大多数常见场景来说变得非常笨重了.最后,添加了另一层 ...

  8. H5 canvas 实现飞机大战游戏

    首先看几张效果图: 上面三张图分别对应游戏的三种状态 ready,play,pause.体验一下 先介绍一下canvas 画图的原理,在这个游戏中的背景,飞机,子弹以及飞机被击中爆炸的效果都是一张张的 ...

  9. [基础知识]在PeopleSoft中SMTP设置不生效如何查找问题

    在PeopleSoft中如果配置了工作流邮件或者标准页面的通知,都是可以发送出邮件的,这些邮件都是由SMTP服务器发送.SMTP需要在APP服务器和PRCS服务器中配置. 如果无法从PeopleSof ...

  10. 记一次寻找appbug的问题

    公司规模 3000人以上 全国500强. 从总部刚交接过来的代码. 1.找不到代码.代码部分丢失.(由于没有交接,没有任何相关文档,花了一天确定代码丢失.从总部找到部分代码) 2.查找测试库,发现测试 ...