vlpap

quotes_spider_pt3.py

Feb 25th, 2021
455
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×