首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scrapy跟随链接但不返回数据,可能是计时问题?

问Scrapy跟随链接但不返回数据,可能是计时问题?
EN

Stack Overflow用户
提问于 2021-05-13 23:18:29
回答 1查看 27关注 0票数 0

我尝试了几种设置,比如延迟下载时间,控制台似乎没有错误,选择器从Scrapy Shell返回正确的数据

网站在域名上使用了不同的前缀,这可能是原因吗?slist.amiami.jp我尝试了几种不同的域名和URL,但都得到了相同的结果,没有返回数据

知道为什么它没有为-o CSV文件收集任何数据吗?如果你有任何建议,谢谢你

预期的输出是从产品页面返回JAN代码和类别文本

代码语言:javascript
复制
2021-05-13 23:59:35 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2021-05-13 23:59:35 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6026
2021-05-13 23:59:40 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://example.jp/top/search/list?s_keywords=4967834601246> (referer: None)
2021-05-13 23:59:46 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.example.jp/top/detail/detail?gcode=TOY-SCL-05454> (referer: https://example.jp/top/search/list?s_keywords=4967834601246)
2021-05-13 23:59:50 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://example.jp/top/search/list?s_keywords=4543736302216> (referer: None)
2021-05-14 00:00:04 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://example.jp/top/search/list?s_keywords=44536318620013> (referer: None)
2021-05-14 00:00:04 [scrapy.core.engine] INFO: Closing spider (finished)
2021-05-14 00:00:04 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 1115,
 'downloader/request_count': 4,
 'downloader/request_method_count/GET': 4,
 'elapsed_time_seconds': 29.128242,
 'finish_reason': 'finished',
代码语言:javascript
复制
import scrapy


class exampledataSpider(scrapy.Spider):
    name = 'example'
    allowed_domains = ['example.jp']
    start_urls = ['https://example.jp/top/search/list?s_keywords=4967834601246',
                  'https://example.jp/top/search/list?s_keywords=4543736302216',
                  'https://example.jp/top/search/list?s_keywords=44536318620013',

                  ]

    def parse(self, response):
        for link in response.css('div.product_box a::attr(href)'):
            yield response.follow(link.get(), callback=self.item)


    def item(self, response):
        products = response.css('div.maincontents')
        for product in products:
            yield {
                'JAN': product.css('dd.jancode::text').getall(),
                'title': product.css('div.pankuzu a::text').getall()
            }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-14 06:46:46

看起来products = response.css('div.maincontents')选择器是不正确的,我不得不对数据做了两次不同的父子请求

这也证明了你可以简单地将列表中的元素

“”“

def output(self,response):

代码语言:javascript
复制
    yield {
        'firstitem': response.css('example td:nth-of-type(2)::text').getall(),
        'seconditem': response.css('example td:nth-of-type(2)::text').getall(),
        'thrditem': response.css('example td:nth-of-type(2)::text').getall()
    }

“”“

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67521775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档