我有一个问题,我已经开始在 BeautifulSoup 上使用 Scrapy 并且我是 Scrapy 的新手,所以这个错误让我失望了,我试图修复它但没有成功。我想使用 Item Loader 来生成报废的项目,但出现错误,我不明白是什么问题。有人可以向我解释我做错了什么。这是我的蜘蛛代码,quotes.py:from scrapy import Spiderfrom scrapy.loader import ItemLoaderfrom quotes_spider.items import QuotesSpiderItemclass QuotesSpider(Spider): name = 'quotes' allowed_domains = ['http://quotes.toscrape.com'] start_urls = ["http://quotes.toscrape.com"] def parse(self, response): l = ItemLoader(item=QuotesSpiderItem(), response=response) quotes = response.xpath('//*[@class="quote"]') for quote in quotes: text = quote.xpath('.//*[@class="text"]/text()').extract_first() author = quote.xpath('.//*[@itemprop="author"]/text()').extract_first() tags = quote.xpath('.//*[@class="tag"]/text()').extract_first () l.add_value('Text', text) l.add_value('Author', author) l.add_value('Tags', tags) return l.load_item()这是我的 items.py 文件:import scrapyclass QuotesSpiderItem(scrapy.Item): text = scrapy.Field() author = scrapy.Field() tags = scrapy.Field()这是我尝试运行它时遇到的错误:Traceback (most recent call last): File "/home/djurovic/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 654, in _runCallbacks current.result = callback(current.result, *args, **kw) File "/home/djurovic/Desktop/quotes_spider/quotes_spider/spiders/quotes.py", line 20, in parse l.add_value('Text', text) File "/home/djurovic/.local/lib/python3.6/site-packages/scrapy/loader/__init__.py", line 77, in add_value self._add_value(field_name, value) File "/home/djurovic/.local/lib/python3.6/site-packages/scrapy/loader/__init__.py", line 91, in _add_value processed_value = self._process_input_value(field_name, value) File "/home/djurovic/.local/lib/python3.6/site-packages/scrapy/loader/__init__.py", line 148, in _process_input_value proc = self.get_input_processor(field_name)
添加回答
举报
0/150
提交
取消