How to use the library requests (in python) after a request
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
bot = requests.session
Simple way to convert cookies into list of dicts and save to json or db.
This is methods of class which have session attribute.
def dump_cookies(self):
cookies = []
for c in self.session.cookies:
cookies.append({
"name": c.name,
"value": c.value,
"domain": c.domain,
"path": c.path,
"expires": c.expires
})
return cookies
def load_cookies(self, cookies):
for c in cookies:
self.session.cookies.set(**c)
All we need is five parameters such as: name, value, domain, path, expires