Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
BiliDriveEx
提交
8fd0bd3e
B
BiliDriveEx
项目概览
OpenDocCN
/
BiliDriveEx
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
BiliDriveEx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8fd0bd3e
编写于
3月 06, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化代码结构
上级
9281bf98
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
31 deletion
+32
-31
BiliDriveEx/bilibili.py
BiliDriveEx/bilibili.py
+32
-31
未找到文件。
BiliDriveEx/bilibili.py
浏览文件 @
8fd0bd3e
...
...
@@ -77,7 +77,6 @@ class Bilibili:
def
login_once
(
self
,
username
,
password
,
captcha
=
None
):
key
=
self
.
get_key
()
print
(
'key: '
,
key
)
key_hash
,
pub_key
=
key
[
'key_hash'
],
key
[
'pub_key'
]
username
=
parse
.
quote_plus
(
username
)
password
=
parse
.
quote_plus
(
base64
.
b64encode
(
rsa
.
encrypt
(
f
'
{
key_hash
}{
password
}
'
.
encode
(),
pub_key
)))
...
...
@@ -86,7 +85,8 @@ class Bilibili:
if
captcha
:
param
+=
f
'&captcha=
{
captcha
}
'
param
+=
f
"&password=
{
password
}
&username=
{
username
}
"
payload
=
f
"
{
param
}
&sign=
{
self
.
calc_sign
(
param
)
}
"
headers
=
{
'Content-type'
:
"application/x-www-form-urlencoded"
}
headers
=
Bilibili
.
default_hdrs
.
copy
()
headers
.
update
({
'Content-type'
:
"application/x-www-form-urlencoded"
})
res
=
self
.
_requests
(
"POST"
,
url
,
data
=
payload
,
headers
=
headers
).
json
()
return
res
...
...
@@ -99,37 +99,38 @@ class Bilibili:
# 登录
def
login
(
self
,
username
,
password
):
captcha
=
None
while
True
:
response
=
self
.
login_once
(
username
,
password
)
print
(
response
)
while
True
:
if
response
and
response
.
get
(
"code"
)
is
not
None
:
if
response
[
'code'
]
==
-
105
:
response
=
self
.
get_captcha
()
captcha
=
self
.
_solve_captcha
(
response
)
if
captcha
:
log
(
f
"登录验证码识别结果:
{
captcha
}
"
)
response
=
self
.
login_once
(
username
,
password
,
captcha
)
else
:
log
(
f
"登录验证码识别服务暂时不可用, 10秒后重试"
)
time
.
sleep
(
10
)
break
elif
response
[
'code'
]
==
-
449
:
time
.
sleep
(
1
)
response
=
self
.
login_once
(
username
,
password
)
elif
response
[
'code'
]
==
0
and
response
[
'data'
][
'status'
]
==
0
:
print
(
response
)
for
cookie
in
response
[
'data'
][
'cookie_info'
][
'cookies'
]:
self
.
_session
.
cookies
.
set
(
cookie
[
'name'
],
cookie
[
'value'
],
domain
=
".bilibili.com"
)
log
(
"登录成功"
)
return
True
else
:
log
(
f
"登录失败
{
response
}
"
)
return
False
response
=
self
.
login_once
(
username
,
password
,
captcha
)
if
not
response
or
'code'
not
in
response
:
log
(
f
"当前IP登录过于频繁, 1分钟后重试"
)
time
.
sleep
(
60
)
continue
if
response
[
'code'
]
==
-
105
:
response
=
self
.
get_captcha
()
captcha
=
self
.
_solve_captcha
(
response
)
if
captcha
:
log
(
f
"登录验证码识别结果:
{
captcha
}
"
)
else
:
log
(
f
"当前IP登录过于频繁, 1分钟后重试"
)
time
.
sleep
(
60
)
break
log
(
f
"登录验证码识别服务暂时不可用, 10秒后重试"
)
time
.
sleep
(
10
)
continue
if
response
[
'code'
]
==
-
449
:
time
.
sleep
(
1
)
continue
if
response
[
'code'
]
==
0
and
response
[
'data'
][
'status'
]
==
0
:
for
cookie
in
response
[
'data'
][
'cookie_info'
][
'cookies'
]:
self
.
_session
.
cookies
.
set
(
cookie
[
'name'
],
cookie
[
'value'
],
domain
=
".bilibili.com"
)
log
(
"登录成功"
)
return
True
log
(
f
"登录失败
{
response
}
"
)
return
False
# 获取用户信息
def
get_user_info
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录