Advertisement
vlpap

quotes_spider_pt3.py

Feb 25th, 2021
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import scrapy
  2.  
  3. class QuotesSpider(scrapy.Spider):
  4.     name = "quotes_pt3"
  5.    
  6.     start_urls = ['http://quotes.toscrape.com/page/1/']
  7.    
  8.     def parse(self, response):
  9.         for quote in response.css('div.quote'):
  10.             yield {
  11.                 'text' : quote.css('span.text::text').get(),
  12.                 'author' : quote.css('small.author::text').get(),
  13.                 'tags' : quote.css('div.tags a.tag::text').getall(),
  14.             }
  15.            
  16.         next_page = response.css('li.next a::attr(href)').get()
  17.         if next_page is not None:
  18.             next_page = response.urljoin(next_page)
  19.             yield scrapy.Request(next_page, callback=self.parse)
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement