def parse(self, response):
    hxs = HtmlXPathSelector(response)
if hxs.select("//form[@id='UsernameLoginForm_LoginForm']"):
    return self.login(response)
else:
    return self.get_section_links(response)
Using Scrapy with authenticated (logged in) user session