add scrapy
This commit is contained in:
19
quotes_spider.py
Normal file
19
quotes_spider.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import scrapy
|
||||
|
||||
class QuoteSpider(scrapy.Spider):
|
||||
name = "quotes"
|
||||
start_urls = [
|
||||
'http://quotes.toscrape.com/tag/humor/',
|
||||
]
|
||||
|
||||
def parse(self, response):
|
||||
for quote in response.css('div.quote'):
|
||||
yield {
|
||||
'author': quote.css('small.author::text').get(),
|
||||
'text': quote.css('span.text::text').get(),
|
||||
# 'tags': quote.css('div.tags a.tag::text').getall(),
|
||||
}
|
||||
|
||||
next_page = response.css('li.next a::attr(href)').get()
|
||||
if next_page is not None:
|
||||
yield response.follow(next_page, callback=self.parse)
|
||||
Reference in New Issue
Block a user