I'm trying to do the following:
- log into a web page (in my case zendesk.com)
- use that session to do some post requests
In fact zendesk misses some apis (create/alter macros) which I now need to simulate simulating a browser session.
So I'm not writing a spider but try to interact with the website as my script proceeds. The post requests are not known from the start but only during my script.
In the Scrapy docs, there is the following example to illustrate how to use an authenticated session in Scrapy:
class LoginSpider(BaseSpider):
name = 'example.com'
start_urls = ['http://www.example.com/users/login.php']
def parse(self, response):
return [FormRequest.from_response(response,
formdata={'username': 'john', 'password': 'secret'},
callback=self.after_login)]
def after_login(self, response):
# check login succeed before going on
if "authentication failed" in response.body:
self.log("Login failed", level=log.ERROR)
return
# continue scraping with authenticated session...
But it looks like this only works for scraping, but in my case I just want to "hold" the session and further work with that session. Is there a way to achieve this with scrapy, or are there tools that better fit this task?