Created
June 29, 2019 07:47
-
-
Save LittleYenMin/e4ac0f640269b7a3f90cb13b90ebcd6c to your computer and use it in GitHub Desktop.
Crawler demo in scrapy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scrapy | |
class QuotesSpider(scrapy.Spider): | |
name = 'quotes' | |
start_urls = [ | |
'http://quotes.toscrape.com/tag/humor/', | |
] | |
def parse(self, response): | |
for quote in response.xpath('//div[contains(@class, "quote")]'): | |
yield { | |
'text': quote.xpath('span[contains(@class, text)]/text()').get(), | |
'author': quote.xpath('span/small/text()').get(), | |
} | |
next_page = response.xpath('//li[contains(@class, "next")]/a/@href').get() | |
if next_page is not None: | |
yield response.follow(next_page, self.parse) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment