Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.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 刮片错误:异常。ValueError:请求url中缺少方案:_Python_Scrapy - Fatal编程技术网

Python 刮片错误:异常。ValueError:请求url中缺少方案:

Python 刮片错误:异常。ValueError:请求url中缺少方案:,python,scrapy,Python,Scrapy,我使用try except来避免错误,但我的终端仍然显示错误,但不显示日志消息: raise ValueError('Missing scheme in request url: %s' % self._url) exceptions.ValueError: Missing scheme in request url: 当scrapy没有获取图像URL时,如何避免此错误? 请引导我,非常感谢 try: item['image_urls'] = ["".join(im

我使用
try except
来避免错误,但我的终端仍然显示错误,但不显示日志消息:

raise ValueError('Missing scheme in request url: %s' % self._url)
exceptions.ValueError: Missing scheme in request url: 
当scrapy没有获取图像URL时,如何避免此错误?
请引导我,非常感谢

    try:

        item['image_urls'] = ["".join(image.extract()) ]     
    except:
        log.msg("no image foung!. url={}".format(response.url),level=log.INFO)

image\u url
字段应该是列表,而不是str

item['image_urls'] = image.extract()
如果您这样做了,但仍然引发异常,那么您抓取的URL似乎是相对路径

ImagePipeline
不知道您的主机,因此无法生成爬网的绝对路径

import urlparse
item['image_urls'] = [ urlparse.urljoin(response.url, u) for u in image.extract() ]

“请求url中缺少方案”意味着您缺少url的“http://”部分,很可能是因为您的url是相对的,应该是绝对的。

在python 3.6中,它是来自urllib.parse import urljoin和
…[urljoin(…