如何修复“Typeerror<”请求url必须是str或unicode got%s:'>

2024-09-28 19:07:25 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我是新来的,创造了我的第一只蜘蛛。但我发现了输入错误

这个蜘蛛只是从goodreads的第一页中删除引用。它有30个引号,带标签和作者姓名

import scrapy

class Goodreadspider(scrapy.Spider):

    name = 'goodreads'

    def start_requests(self):
        url = ['https://www.goodreads.com/quotes?page=1']
        yield scrapy.Request(url=url, callback=self.parse)
    def parse(self, parse):
        for quote in response.selector.xpath("//div[@class='quote']"):
            yield{
            'text': quote.xpath("//div[@class='quoteText']/text()[1]").extract_first,
            'author': quote.xpath("//div[@class='quoteText']/child::a/text()").extract_first,
            'tags': quote.xpath("//div[@class='greyText smallText left']/a/text()").extract()
            }

Typeerror<'Request url must be str or unicode, got %s:'


Tags: textselfdivurlparserequestdefextract
2条回答

我认为你有这个错误,因为你试图传递一个列表,而不是str或unicode,就像ask by“scrapy.Request”

试试这个:

def start_requests(self):
        url = 'https://www.goodreads.com/quotes?page=1'
        yield scrapy.Request(url=url, callback=self.parse)

应该有用

是否尝试删除[]

url = 'https://www.goodreads.com/quotes?page=1'

相关问题 更多 >