|
import scrapy
from Demo.items import DemoItem
class QuotesSpider(scrapy.Spider):
name = 'quotes'
allowed_domains = ['quores.toscrape.com
start_urls = ['http://quotes.toscrape.com/'
def parse(self, resp**e):
quotes = resp**e.css('.quote')
for quote in quotes:
item = DemoItem()
text = quote.css('.text::text').extract_first()
author = quote.css('.author::text').extract_first()
tags = quote.css('.tags .tag::text').extract()
item['text'] = text
item['author'] = author
item['tags'] = tags
yield item
next = resp**e.css('.pager .next a::attr("href")').extract_first()
url = resp**e.urljoin(next)
if next:
yield scrapy.Request(url=url,callback=self.parse)
|
|