I scrap successfully data for a single account. I want to scrap multiple accounts on a single website, multiple accounts needs multiple logins, I want a way how to manage login/logout ?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
you can scrape multiples accounts in parallel using multiple cookiejars per account session, see "cookiejar" request meta key at http://doc.scrapy.org/en/latest/topics/downloader-middleware.html?highlight=cookiejar#std:reqmeta-cookiejar
To clarify: suppose we have an array of accounts in
settings.py
:And this is the link to the login page:
http://example.com/login
Create
start_requests
function in your spider, in this function we can loop on theMY_ACCOUNTS
array and login to each account:form_login_name
andform_pwd_name
are respectively fields names on the login form.dont_filter=True
For ignoring filter on duplicate requests, because here we make a POST request to login on the same pagehttp://example.com/login
request.meta['cookiejar'] = i
to separate cookies of each session(login), dont forget to addcookiejar
identifier in your sub request, suppose you want to redirect scrapy to a page after login: