【问题标题】:crawl pictures from web site with Scrapy使用 Scrapy 从网站抓取图片
【发布时间】:2013-09-04 09:58:32
【问题描述】:

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

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

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

管道.py。 :https://gist.github.com/nahali/6434932

settings.py:

【问题讨论】:

  • 你有什么错误?您可以将 gist 中的错误日志添加为新文件
  • 在你的蜘蛛中我看不到你在哪里设置item["image_urls"]。您需要在item["image_urls"]中设置要获取的列表或图片网址
  • 我想我在 item["image_urls"] 中有一个图像列表,但我是新手,所以我只是尝试关注doc.scrapy.org/en/latest/topics/images.html
  • 你是保罗·特雷伯斯吗?

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


【解决方案1】:

你的parse_wine_page没有在items中设置“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 类具有“images”和“image_urls”字段()

【讨论】:

  • 谢谢保罗,ca mache j'ai eu les Liens mais je veux qu'ils téléchargé dans un fichier et le visualiser sur le svc
  • CSV 文件应包含“图像”列中图像的文件路径。我不知道您是否或如何在 CSV 查看器中显示图像
猜你喜欢
  • 2013-05-09
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多