How to save requests (python) cookies to a file?

前端 未结 10 1712
渐次进展
渐次进展 2020-11-30 17:35

How to use the library requests (in python) after a request

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
bot = requests.session         


        
10条回答
  •  佛祖请我去吃肉
    2020-11-30 17:45

    This will do the job:

    session.cookies = LWPCookieJar('cookies.txt')
    

    The CookieJar API requires you to call load() and save() manually though. If you do not care about the cookies.txt format, I have a ShelvedCookieJar implementation that will persist on change.

提交回复
热议问题