使用Scrapy从网站抓取图片

时间:2013-09-04 09:58:32

标签: python web-scraping scrapy extraction html-content-extraction

我想从 vinnicolas 的网站抓取每瓶葡萄酒的图像并将其保存在svc文件中。

不幸的是,我遇到了一些错误:

蜘蛛:https://gist.github.com/anonymous/6424305

pipelines.py。 :https://gist.github.com/nahali/6434932

settings.py:

1 个答案:

答案 0 :(得分:0)

您的parse_wine_page未在项目中设置“image_urls”字段值,因此中间件不会下载任何图片

import urlparse
...

    def parse_wine_page(self, reponse):
        ...
        hxs = HtmlXPathSelector(response)
        content = hxs.select('//*[@id="glo_right"]')
        for res in content:
            ...
            #item ["Image"]= map(unicode.strip, res.select('//div[@class="pro_detail_tit"]//div[@class="pro_titre"]/h1/text()').extract())
            item['image_urls'] = map(lambda src: urlparse.urljoin(response.url, src), res.select('./div[@class="pro_col_left"]/img/@src').extract())
            items.append(item)
        return items

同时确保您的Projetvinnicolas3Item班级有“图片”和“image_urls”字段()

相关问题