# -*- coding: utf-8 -*-
import scrapy


class QuotesToscrapeSpider(scrapy.Spider):
    name = 'quotes-toscrape'
    allowed_domains = ['quotes.toscrape.com']
    start_urls = ['http://quotes.toscrape.com/']

    def parse(self, response):
        for quote in response.css("div.quote"):
            yield {
                'text': quote.css("span.text ::text").extract_first(),
                'author': quote.css("small.author ::text").extract_first(),
                'tags': quote.css("div.tags > a.tag ::text").extract()
            }
        next_page_url = response.css("nav > ul > li.next > a ::attr(href)").extract_first()
        if next_page_url:
            yield scrapy.Request(response.urljoin(next_page_url))

