comwrg / bilibiliupload

This project is not maintained anymore.
MIT License
140 stars 35 forks source link

Saving cookie file for logins #57

Closed sideloading closed 4 years ago

sideloading commented 4 years ago

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

comwrg commented 4 years ago

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

sideloading commented 4 years ago

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)