Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

scrapy

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)
like image 776
user2492364 Avatar asked Dec 17 '14 00:12

user2492364


1 Answers

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() ]
like image 143
soooooot Avatar answered Sep 19 '22 11:09

soooooot