python requests 简单实现易班登录,自动点赞,评论,发表
小编能力有限,本文纯属瞎编,如有异议,你去打辅导员涩
一.前戏
有个操蛋,操蛋,操蛋的辅导员促使小编成长,原因:易班需要活跃度,辅导员安排班上每个人必须去易班上 写文章,写评论,发投票... 我觉得辅导员肯定小瞧我们了,我们班像好好刷易班的人嘛。
结果就鸡儿了涩,都没去发。直接导致辅导员强行安排(早上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 简单实现易班登录,自动点赞,评论,发表的更多相关文章
- 一种让运行在CentOS下的.NET CORE的Web项目简单方便易部署的自动更新方案
一.项目运行环境 项目采用的是.NET5开发的Web系统,独立部署在省内异地多台CentOS服务器上,它们运行在甲方专网环境中(不接触互联网),甲方进行业务运作时(一段时间内)会要求异地服务器开机上线 ...
- java 实现类似于python requests包的Session类,自动管理cookie。
1.在py中requests.post()和get()函数都是在那个函数内部里面自动生成了一个Session类的实例,所以requests,post和get函数要想干登陆后才能干的事情,需要添加coo ...
- python requests简单接口自动化
get方法 url:显而易见,就是接口的地址url啦 headers:定制请求头(headers),例如:content-type = application/x-www-form-urlencode ...
- python requests实现windows身份验证登录
1.安装ntlm https://github.com/requests/requests-ntlm pip install requests_ntlm 2.使用 import requests f ...
- python+requests 请求响应文本出错返回“登录超时”
Python+requests请求响应:"msg":"登录过时" 1.出错原代码: import requests import json#页面按条件搜索返回相 ...
- Python:requests库、BeautifulSoup4库的基本使用(实现简单的网络爬虫)
Python:requests库.BeautifulSoup4库的基本使用(实现简单的网络爬虫) 一.requests库的基本使用 requests是python语言编写的简单易用的HTTP库,使用起 ...
- Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据
Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...
- Python requests模拟登录
Python requests模拟登录 #!/usr/bin/env python # encoding: UTF-8 import json import requests # 跟urllib,ur ...
- 一个简单、易用的Python命令行(terminal)进度条库
eprogress 是一个简单.易用的基于Python3的命令行(terminal)进度条库,可以自由选择使用单行显示.多行显示进度条或转圈加载方式,也可以混合使用. 示例 单行进度条 多行进度条 圆 ...
随机推荐
- 撩课-Web大前端每天5道面试题-Day31
1.web storage和cookie的区别? Web Storage的概念和cookie相似, 区别是它是为了更大容量存储设计的. Cookie的大小是受限的, 并且每次你请求一个新的页面的时候C ...
- LINQ to Objects系列(4)表达式树
为了进一步加深对Lambda表达式的理解,我们需要掌握一个新的知识,Lambda表达式树,可能听名字看起来很高深和难以理解,但实际上理解起来并没有想象中那么难,这篇文章我想分以下几点进行总结. 1,表 ...
- HDU2157(SummerTrainingDay05-F dp)
How many ways?? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- python 字符串与列表的相互转换 数据类型转换
Python数据类型之间的转换 函数 描述 int(x [,base]) 将x转换为一个整数 long(x [,base] ) 将x转换为一个长整数 float(x) 将x转换到一个浮点数 compl ...
- 移动端开发在iOS系统中 new Date() 返回 NaN 的问题
问题: 通过 new Date() 函数将后台返回的时间('2021-11-25')获取时间戳.在 chrome 浏览器的手机模拟器中没有出现问题,但在 iPhone 真机测试的时候,显示的结果不符合 ...
- js-ES6学习笔记-module(2)
1.如果想为输入的变量重新取一个名字,import命令要使用as关键字,将输入的变量重命名. import { lastName as surname } from './profile'; 2.im ...
- 关于Web中列表页面的加载问题
2017年5月23日,天气晴朗.尽管昨晚睡的不踏实,好在今天心情还不是很糟糕,近来事情颇多,尤其是对于TA的改变,至少目前还是没有习惯,但时间将会解决一切,这点深有体会.此时此刻,又想起了苏东坡的那首 ...
- OSGI企业应用开发(三)Eclipse中搭建Equinox运行环境
上篇文章介绍了如何在Eclipse中搭建Felix的运行环境,我们需要將Bundle发布到Felix框架的bundle目录下,Felix框架启动时才会自动加载这些Bundle,否则需要在Felix框架 ...
- 安卓socket聊天
安卓基于Socket通信(服务器配合) 1.话不多说进入正题,先创建服务端,在Android Studio中创建Java代码,如下图所示: 选择Java Library 需要改名字的自己随意 2.创建 ...
- jsp隐式对象
隐式对象使用位置 隐式对象在转译为Servlet后,是_jspService()中的局部变量.隐式对象只能在<%与%>之间,或<%=与%>之间直接使用. 无法在<%!与% ...