import browsercookie
from scrapy.downloadermiddlewares.cookies import CookiesMiddleware
class BrowserCookiesMiddleware(CookiesMiddleware):
def init(self, debug=False):
super().init(debug)
self.load_browser_cookies()
def load_browser_cookies(self):
jar = self.jars['chrome']
chrome_cookiejar = browsercookie.chrome()
for cookie in chrome_cookiejar:
jar.set_cookie(cookie)
# jar = self.jars['firefox']
# firefox_cookiejar = browsercookie.firefox()
# for cookie in firefox_cookiejar:
# jar.set_cookie(cookie)