【发布时间】:2019-04-08 11:29:30
【问题描述】:
我编写了一个简单的蜘蛛来检索引号信息:
import scrapy
class GoodReadsSpider(scrapy.Spider):
#identity
name = 'goodreads'
#requests
def start_requests(self):
url = "https://www.goodreads.com/quotes?page=1",
yield scrapy.Request(url=url, callback= self.parse)
#response
def parse(self, response):
for quote in response.selector.xpath("//div[@class='quote']"):
yield {
'text': quote.xpath(".//blockquote[@class='quoteBody']/text()[1]").extract_first(),
'author': quote.xpath(".//span[@class='quoteAuthor']/text()").extract_first(),
'tag': quote.xpath(".//div[@class='quoteTags']/a/text()").extract(),
}
当我运行它时,我得到以下错误:
Request url must be str or unicode, got %s:' % type(url).__name__
有人知道为什么吗?
【问题讨论】:
-
因为你的 URL 是一个tuple,因为它的定义中有尾随逗号。实际消息应该告诉您这一点 - 您发布的是引发该错误的行,而不是结果消息。
标签: python-3.x web-scraping request scrapy