From b2f38791372acbf9b8e2e87c23acceffb9a1aac2 Mon Sep 17 00:00:00 2001 From: Anthony Chou Date: Mon, 21 Oct 2019 17:24:20 +0800 Subject: [PATCH] Update method names --- quotesbot/spiders/toscrape-css.py | 8 ++++---- quotesbot/spiders/toscrape-xpath.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/quotesbot/spiders/toscrape-css.py b/quotesbot/spiders/toscrape-css.py index 555e204..9e3fd79 100644 --- a/quotesbot/spiders/toscrape-css.py +++ b/quotesbot/spiders/toscrape-css.py @@ -11,12 +11,12 @@ class ToScrapeCSSSpider(scrapy.Spider): def parse(self, response): for quote in response.css("div.quote"): yield { - 'text': quote.css("span.text::text").extract_first(), - 'author': quote.css("small.author::text").extract_first(), - 'tags': quote.css("div.tags > a.tag::text").extract() + 'text': quote.css("span.text::text").get(), + 'author': quote.css("small.author::text").get(), + 'tags': quote.css("div.tags > a.tag::text").getall() } - next_page_url = response.css("li.next > a::attr(href)").extract_first() + next_page_url = response.css("li.next > a::attr(href)").get() if next_page_url is not None: yield scrapy.Request(response.urljoin(next_page_url)) diff --git a/quotesbot/spiders/toscrape-xpath.py b/quotesbot/spiders/toscrape-xpath.py index 9599fd8..bbca69c 100644 --- a/quotesbot/spiders/toscrape-xpath.py +++ b/quotesbot/spiders/toscrape-xpath.py @@ -11,12 +11,12 @@ class ToScrapeSpiderXPath(scrapy.Spider): def parse(self, response): for quote in response.xpath('//div[@class="quote"]'): yield { - 'text': quote.xpath('./span[@class="text"]/text()').extract_first(), - 'author': quote.xpath('.//small[@class="author"]/text()').extract_first(), - 'tags': quote.xpath('.//div[@class="tags"]/a[@class="tag"]/text()').extract() + 'text': quote.xpath('./span[@class="text"]/text()').get(), + 'author': quote.xpath('.//small[@class="author"]/text()').get(), + 'tags': quote.xpath('.//div[@class="tags"]/a[@class="tag"]/text()').getall() } - next_page_url = response.xpath('//li[@class="next"]/a/@href').extract_first() + next_page_url = response.xpath('//li[@class="next"]/a/@href').get() if next_page_url is not None: yield scrapy.Request(response.urljoin(next_page_url))