如何在python的scrapy中启用cookiemiddleware [英] How to enable cookiemiddleware in scrapy in python
问题描述
在他们的文档中 http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#cookies-mw
他们告诉启用 cookie 中间件,但我无法找到如何执行此操作以及为此编辑哪个文件.谁能告诉我我该怎么做
They told to enable the cookie middle , but i am not able to find how to do that and which file to edit for that. Can anyone tell me how can i do that
推荐答案
update 会出现 cookie 默认在中间件中,所以只要 COOKIES_ENABLED = True
应该是充足的.如果中间件不是默认值的一部分,您只需要以下...
update it would appear cookies are in the middleware by default, so just COOKIES_ENABLED = True
should be sufficient. You only need the below if the middleware is not part of the defaults...
据我从 doc.scrapy.org/en/latest/topics/downloader-middleware.html 中得知,您添加'scrapy.contrib.downloadermiddleware.cookies.CookiesMiddleware'
到带有相关顺序的 DOWNLOADER_MIDDLEWARE:
From what I can tell from doc.scrapy.org/en/latest/topics/downloader-middleware.html you add
'scrapy.contrib.downloadermiddleware.cookies.CookiesMiddleware'
to DOWNLOADER_MIDDLEWARE with a relevant ordering:
要激活下载器中间件组件,请将其添加到DOWNLOADER_MIDDLEWARES 设置,这是一个字典,其键是中间件类路径及其值是中间件顺序.
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然后将 COOKIES_ENABLED = True
(以及可选的 COOKIES_DEBUG = True
)与您的其余设置放在一起.
The 700 comes from the default DOWNLOADER_MIDDLEWARES_BASE
at http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#built-in-downloader-middleware-reference
Then put COOKIES_ENABLED = True
(and optionally COOKIES_DEBUG = True
) with the rest of your settings.
这篇关于如何在python的scrapy中启用cookiemiddleware的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!