在他们的文档中 http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#cookies-mw
他们告诉我启用 cookie middle ,但我无法找到如何做到这一点以及为此编辑哪个文件。谁能告诉我我该怎么做
最佳答案
更新 cookie 似乎默认位于中间件中,因此只需 COOKIES_ENABLED = True
就足够了。如果中间件不是默认设置的一部分,则只需要以下内容...
据我从 doc.scrapy.org/en/latest/topics/downloader-middleware.html 可以看出你添加
'scrapy.contrib.downloadermiddleware.cookies.CookiesMiddleware'
到具有相关顺序的 DOWNLOADER_MIDDLEWARE:
To activate a downloader middleware component, add it to the DOWNLOADER_MIDDLEWARES setting, which is a dict whose keys are the middleware class paths and their values are the middleware orders.
DOWNLOADER_MIDDLEWARES = {
'myproject.middlewares.CustomDownloaderMiddleware': 543,
'scrapy.contrib.downloadermiddleware.cookies.CookiesMiddleware': 700 # <-
}
700 来自 http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#built-in-downloader-middleware-reference 处的默认 DOWNLOADER_MIDDLEWARES_BASE
然后将 COOKIES_ENABLED = True
(以及可选的 COOKIES_DEBUG = True
)与您的其余设置一起放置。
关于python - 如何在python中的scrapy中启用cookiemiddleware,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13488106/