scrapy实现browsercookie中间件

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)
上一篇:session详细认识并且用代码运用了解里面的方法及特点作用


下一篇:H5 APP 使用 JSESSIONID 保持会话登录