Reuse Auth State
How to preserve authenticated status across sessions.
For any web service that requires authentication, you’ll want to save your cookies and local storage and re-use them for every session. Otherwise, you’ll need to log in each time, and each execution will be treated as a new browser by the service. This slows your automation down, and can lead to rate rate limits or other obstacles if the service detects many logins from different browsers in a short period of time.
In order to save the browser state, call finic.save_browser_state()
each time after your automation completes a login attempt.
Example:
This saves your browser state to browser_state.json
. The next time the automation runs, it will check for browser_state.json
and if it exists, will load the cookies and local
storage objects into memory. For most websites, this means the automation does not need to login in again unless the session has been invalidated by the service.