Scrapy 在 shell 中有效,但在代码中无效

迭戈·佩斯科市长

我在用scrapy开发我的第一个蜘蛛时遇到了一个问题。我能够在scrapy shell中获得正确的信息,但是当我在代码中实现它时它不起作用。我在这里读过类似的帖子,但我仍然无法弄清楚我做错了什么。

import scrapy
from scrapy.loader import ItemLoader
from ..items import ScrapingamazonItem

class AmazonSpiderSpider(scrapy.Spider):
    name = 'amazon_spider'
    start_urls = ['https://www.amazon.com/s?k=Office+Chair&lo=grid&crid=1N60K12GUA798&qid=1601040579&sprefix=chair&ref=sr_pg_1']

    def parse(self, response):
        items = response.css('.s-asin .sg-col-inner')

        for item in items:
            loader = ItemLoader(item=ScrapingamazonItem(), selector=item)
            loader.add_css('ProductName', '.a-color-base.a-text-normal::text')
        
        yield loader.load_item()

我正在使用scrapy crawl amazon_spider -o file.csv 运行它。该文件返回空。

任何帮助深表感谢!:)

亚伦

尝试

for item in items:
   loader = ItemLoader(item=ScrapingamazonItem(), selector=item)
   loader.add_css('ProductName', '.a-color-base.a-text-normal::text')
   yield loader.load_item()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Scrapy - Xpath 在 shell 中工作,但在代码中无效

git clone在git shell中有效,但在Windows命令行中无效

日期查询在 Mongo shell 中有效,但在 Node 中无效

Xclip命令在Shell中有效,但在键盘快捷方式中无效

此命令在终端中有效,但在Shell脚本中无效

Set-AzContext在Azure Cloud Shell中有效,但在Azure PowerShell中无效

导出变量在终端中有效,但在 shell 脚本中无效

命令在脚本(或-c)中有效,但在直接运行时(在交互式shell中)则无效

fish shell:为什么`file`which command`在zsh和bash中有效,但在fish中无效?

为什么此查询在mongo shell中有效,但在node mongo驱动程序中无效?

带有scrapy shell的Xpath

括号在bash shell本身有效,但在bash脚本中无效

Scrapy Shell:如何在Shell中执行多行代码?

代码在终端中有效,但在脚本中无效

如何在Scrapy Shell中获得Scrapy响应

Scrapy xpath 在scrapy shell 中返回空列表

Scrapy-301在Shell中重定向

Scrapy请求,蜘蛛中的Shell Fetch()

scrapy 在 shell 中工作,但抓取 0 页

Scrapy似乎已安装,但在python shell中无法导入

mysql查询功能在python shell中有效,但在python中运行时出现ImproperlyConfigured错误

Scrapy Shell不断在终端中返回无效语法

Scrapy Shell和Scrapy Splash

ANSIBLE-Shell任务返回非零返回码,但在终端中有效

无法在django中导入视图,但在django shell中有效

Linux Shell脚本:if / else在bash上有效,但在zsh或sh上无效

特定网页的 Scrapy shell

Scrapy Shell Response 204

Scrapy shell打不开