comwrg/bilibiliupload

Saving cookie file for logins

Closed this issue · 2 comments

Hi,

Using the demo in #18 how can I save the login cookie, so I don't have to sign in every time I upload?

Thanks

You can get cookie from browser, and login via cookie.

Do you know how I could save the login session to a .json file? I believe this works

# -*- coding:utf-8 -*-
from bilibiliupload import *
import json

cookies = None
try:
    # Load the session cookies
    with open('session.json', 'r') as f:
        cookies = json.loads(f)
except:
    # If it fails, never mind, we'll just login again
    pass

b = Bilibili(cookie=cookies)

login_status = b.login('user@qq.com', 'password')
print("Login:", login_status)

# Do whatever 

# Save the session cookie right after logging in
with open('session.json', 'w') as f:
    json.dump(b.session.cookies.get_dict(), f)