IN their documentation here http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#cookies-mw
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
log(cook1) self. log("end cookie2") return Request("http://something.net/some/sa/"+response.headers.getlist('Location')[0],cookies={cook1[0]:cook1[1]}, callback=self. check_login_response) . . .
The spider middleware is a framework of hooks into Scrapy's spider processing mechanism where you can plug custom functionality to process the responses that are sent to Spiders for processing and to process the requests and items that are generated from spiders.
Scrapy Cookies Settings Simply set this setting to True in settings.py file to begin. COOKIES_ENABLED is another setting that controls whether cookies will be sent to the web server or not. By default this setting is True , however you can turn it off by setting it to False if you wish.
Scrapy has a downloader middleware CookiesMiddleware implemented to support cookies. You just need to enable it. It mimics how the cookiejar in browser works.
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...
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:
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 # <-
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With