Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# -*- coding:utf-8 -*-
import scrapy
from scrapy.exceptions import CloseSpider
class LoginSpider(scrapy.Spider):
name = 'login-spider'
start_urls = ['']
def parse(self, response):
self.log('visitei a página de login: {}'.format(response.url))
token = response.css('input[name="csrf_token"]::attr(value)').extract_first()
yield scrapy.FormRequest(
'username': 'john.doe',
'password': 'anything',
'csrf_token': token,
def parse_author_links(self, response):
has_logout_link = response.css('a[href="/logout"]').extract_first()
if not has_logout_link:
raise CloseSpider('falha de autenticação')
self.log('acabei de fazer login')
links = response.css('.quote a[href*=""]::attr(href)').extract()
for link in links:
yield {'link': link}
next_page = response.css(' a::attr(href)').extract_first()
if next_page:
yield scrapy.Request(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.