Skip to content

Commit

Permalink
feat: 密码登录(半成)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed Jul 6, 2022
1 parent 517ff58 commit 3d09e9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion bilibili_api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"""

import json
import webbrowser

import requests
from bilibili_api.utils.Credential import Credential
from bilibili_api.utils.utils import get_api
from bilibili_api.utils.sync import sync
Expand Down Expand Up @@ -173,8 +176,22 @@ def login_with_password(username: str, password: str):
"validate": geetest_data['validate'],
"seccode": geetest_data['seccode']
}
print(sync(sess.request("POST", login_api['url'], params=params, headers={
login_data = json.loads(sync(sess.request("POST", login_api['url'], params=params, headers={
'content-type': 'application/x-www-form-urlencoded',
'user-agent': 'Mozilla/5.0',
"referer": "https://passport.bilibili.com/login"
})).text)
url = login_data['data']['url']
if 'https://passport.bilibili.com/account/mobile/security/managephone/phone/verify' in url:
pass
else:
cookies_list = url.split("&")
sessdata = ""
bili_jct = ""
for cookie in cookies_list:
if cookie[:8] == "SESSDATA":
sessdata = cookie[9:]
if cookie[:8] == "bili_jct":
bili_jct = cookie[9:]
c = Credential(sessdata, bili_jct)
return c
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ httpx~=0.22.0
qrcode~=7.3.1
pycryptodome~=3.15.0
pillow~=9.1.1
requests~=2.24.0
requests~=2.28.1
# ffmpeg-python~=0.2.0

0 comments on commit 3d09e9c

Please sign in to comment.