Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.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
Python Scrapy正在将唯一URL筛选为重复URL_Python_Scrapy_Scrapy Spider - Fatal编程技术网

Python Scrapy正在将唯一URL筛选为重复URL

Python Scrapy正在将唯一URL筛选为重复URL,python,scrapy,scrapy-spider,Python,Scrapy,Scrapy Spider,网址: 是唯一的,但scrapy将这些URL作为重复项进行过滤,而不是将其删除 我将爬行蜘蛛与以下规则一起使用: rules = ( Rule(LinkExtractor(restrict_css=('.resultspagenum'))), Rule(LinkExtractor(allow=('\/mobiles\/smartphones\/[a-zA-Z0-9_.-]*',), ), callback='parse_product'), )` 我不明白这种行为,有人能解释

网址:

  • 是唯一的,但scrapy将这些URL作为重复项进行过滤,而不是将其删除
  • 我将爬行蜘蛛与以下规则一起使用:

    rules = (
        Rule(LinkExtractor(restrict_css=('.resultspagenum'))),
        Rule(LinkExtractor(allow=('\/mobiles\/smartphones\/[a-zA-Z0-9_.-]*',), ), callback='parse_product'),
    )`
    
    我不明白这种行为,有人能解释一下吗?上周同样的代码也在运行。
    根据@paul trmbrth的建议,使用Scrapy 1.3.0版

    ,我重新检查了被删除的代码和网站。Scrapy正在下载链接并过滤这些链接,因为它们是以前下载的。问题是html的“a”标记中的链接属性已从静态链接更改为某些javascript函数:

    <a href='javascript:gtm.traceProductClick("/en-sa/mobiles/smartphones/samsung-galaxy-s7-32gb-dual-sim-lte-gold-188024">
    
    这不是scrapy筛选非唯一URL的问题,而是从“a”标记的“href”属性中提取链接的问题,因为该链接最近发生了更改,我的代码被破坏。
    再次感谢@paul trmbrth

    你确定他们还没有被访问吗?是的,整个网站没有任何内容被废弃。所有链接都被过滤。可能是链接被刮除,但页面上没有任何数据?我可以在shell中下载/刮除单个链接的数据,提到的链接在刮除的shell中运行良好。我建议您共享爬网日志,也可以共享爬行器。默认指纹函数为您的2个示例URL生成不同的指纹。所以scrapy不应该过滤所有的
    page=
    ,因为它过滤它们是因为它们已经被提取了。如果没有带有
    LOG\u LEVEL='DEBUG'
    或代码或两者兼有的日志,就不能说更多。
        def _process_value(value):
        m = re.search('javascript:gtm.traceProductClick\("(.*?)"', value)
        if m:
            return m.group(1)
    
    
    rules = (
        Rule(LinkExtractor(restrict_css=('.resultspagenum'))),
        Rule(LinkExtractor(
            allow=('\/mobiles\/smartphones\/[a-zA-Z0-9_.-]*',),
            process_value=_process_value
        ), callback='parse_product'),
    )