Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何列出使用Scrapy从中获取数据的页面的URL?_Scrapy - Fatal编程技术网

如何列出使用Scrapy从中获取数据的页面的URL?

如何列出使用Scrapy从中获取数据的页面的URL?,scrapy,Scrapy,我是一个真正的初学者,但我一直在到处寻找,似乎找不到解决办法。我正在构建一些爬行器,但我不知道如何识别我的抓取数据来自哪个URL 我的蜘蛛是非常基本的现在,我试图学习,因为我去。 我尝试了在stackoverflow上找到的几行代码,但除了打印函数(我不记得是“URL:+response.request.URL”还是类似的东西。我尝试了很多东西)在代码的解析部分工作之外,我什么都做不到,但在成品率方面我什么都做不到 我可以在输出中添加其他标识符,但理想情况下,我想要我正在努力的项目的URL im

我是一个真正的初学者,但我一直在到处寻找,似乎找不到解决办法。我正在构建一些爬行器,但我不知道如何识别我的抓取数据来自哪个URL

我的蜘蛛是非常基本的现在,我试图学习,因为我去。 我尝试了在stackoverflow上找到的几行代码,但除了打印函数(我不记得是“URL:+response.request.URL”还是类似的东西。我尝试了很多东西)在代码的解析部分工作之外,我什么都做不到,但在成品率方面我什么都做不到

我可以在输出中添加其他标识符,但理想情况下,我想要我正在努力的项目的URL

import scrapy

class FanaticsSpider(scrapy.Spider):
    name = 'fanatics'

    start_urls = ['https://www.fanaticsoutlet.com/nfl/new-england-patriots/new-england-patriots-majestic-showtime-logo-cool-base-t-shirt-navy/o-9172+t-70152507+p-1483408147+z-8-1114341320',
        'https://www.fanaticsoutlet.com/nfl/new-england-patriots/new-england-patriots-nfl-pro-line-mantra-t-shirt-navy/o-2427+t-69598185+p-57711304142+z-9-2975969489',]

    def parse(self, response):

        yield {
            'sale-price': response.xpath('//span[@data-talos="pdpProductPrice"]/span[@class="sale-price"]/text()').re('[$]\d+\.\d+'),
            #'sale-price': response.xpath('//span[@data-talos="pdpProductPrice"]/span[@class="sale-price"]/text()').get(),
            'regular-price': response.xpath('//span[@data-talos="pdpProductPrice"]/span[@class="regular-price strike-through"]/text()').re('[$]\d+\.\d+'),
            #'regular-price': response.xpath('//span[@data-talos="pdpProductPrice"]/span[@class="regular-price strike-through"]/text()').get(),
              }

非常感谢您的帮助。我还没有开始学习任何关于管道的知识,我不确定这是否能解决问题?

您可以简单地在收益中添加url,如下所示:

yield {...,
       'url': response.url,
       ...}

非常感谢。我想我可能已经试过了,但一定是忘记了结尾的逗号…*啊*嗨,我看你是新来的。如果您认为答案解决了问题,请单击绿色复选标记将其标记为“已接受”。这有助于将注意力集中在仍然没有答案的老年人身上。