scrapy error :exceptions.ValueError: Missing scheme in request url:

纵饮孤独 提交于 2019-12-18 21:02:30

问题


I use try except to avoid error,but My terminal still show error but not the log message :

raise ValueError('Missing scheme in request url: %s' % self._url)
exceptions.ValueError: Missing scheme in request url: 

How can I avoid this error when scrapy didn't get image_urls?
Please guide me ,thank you very much.

    try:

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

回答1:


the image_urls field should be a list, not a str.

item['image_urls'] = image.extract()

If you do so, and still raise the exception, it seems that the urls you scraped is the relative path.

the ImagePipeline doesn't know your host, so it can not generate the absolute path to crawl.

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



回答2:


"Missing scheme in request url" means that you are missing the "http://" part of the url, most probably because your URL's are relative and should be absolute.



来源:https://stackoverflow.com/questions/27516339/scrapy-error-exceptions-valueerror-missing-scheme-in-request-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!