0

画像をキャッチするスパイダーを構築しようとしています。スパイダーは動作していますが、動作せず、エラーも発生しません。

クモ:

from urlparse import urljoin
from scrapy.selector import XmlXPathSelector
from scrapy.spider import BaseSpider
from nasa.items import NasaItem

class NasaImagesSpider(BaseSpider):
    name = "nasa.gov"
    start_urls = ('http://www.nasa.gov/multimedia/imagegallery/iotdxml.xml',)

    def parse(self, response):
      xxs = XmlXPathSelector(response)
      item = NasaItem()

      baseLink = xxs.select('//link/text()').extract()[0]
      imageLink = xxs.select('//tn/text()').extract()

      imgList = []
      for img in imageLink:
        imgList.append(urljoin(baseLink, img))

      item['image_urls'] = imgList
      return item

ページ全体を実行し、URL を正しくキャプチャします。私はそれをパイプラインに渡しますが.. 写真はありません。

設定ファイル:

BOT_NAME = 'nasa.gov'
BOT_VERSION = '1.0'

ITEM_PIPELINES = ['scrapy.contrib.pipeline.images.ImagesPipeline']
IMAGE_STORE = '/home/usr1/Scrapy/spiders/nasa/images'

LOG_LEVEL = "DEBUG"
SPIDER_MODULES = ['nasa.spiders']
NEWSPIDER_MODULE = 'nasa.spiders'

USER_AGENT = '%s/%s' % (BOT_NAME, BOT_VERSION)

そして項目ファイル:

from scrapy.item import Item, Field

class NasaItem(Item):
    image_urls = Field()
    images = Field()

および出力ログ:

2012-11-12 07:47:28-0500 [scrapy] INFO: Scrapy 0.14.4 started (bot: nasa)
2012-11-12 07:47:29-0500 [scrapy] DEBUG: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, MemoryUsage, SpiderState
2012-11-12 07:47:29-0500 [scrapy] DEBUG: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, RedirectMiddleware, CookiesMiddleware, HttpCompressionMiddleware, ChunkedTransferMiddleware, DownloaderStats
2012-11-12 07:47:29-0500 [scrapy] DEBUG: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2012-11-12 07:47:29-0500 [scrapy] DEBUG: Enabled item pipelines: 
2012-11-12 07:47:29-0500 [nasa.gov] INFO: Spider opened
2012-11-12 07:47:29-0500 [nasa.gov] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2012-11-12 07:47:29-0500 [scrapy] DEBUG: Telnet console listening on 0.0.0.0:6023
2012-11-12 07:47:29-0500 [scrapy] DEBUG: Web service listening on 0.0.0.0:6080
2012-11-12 07:47:29-0500 [nasa.gov] DEBUG: Crawled (200) <GET http://www.nasa.gov/multimedia/imagegallery/iotdxml.xml> (referer: None)
2012-11-12 07:47:29-0500 [nasa.gov] DEBUG: Scraped from <200 http://www.nasa.gov/multimedia/imagegallery/iotdxml.xml>
#removed output of every jpg link
2012-11-12 07:47:29-0500 [nasa.gov] INFO: Closing spider (finished)
2012-11-12 07:47:29-0500 [nasa.gov] INFO: Dumping spider stats:
{'downloader/request_bytes': 227,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 2526,
 'downloader/response_count': 1,
 'downloader/response_status_count/200': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2012, 11, 12, 12, 47, 29, 802477),
 'item_scraped_count': 1,
 'scheduler/memory_enqueued': 1,
 'start_time': datetime.datetime(2012, 11, 12, 12, 47, 29, 682005)}
2012-11-12 07:47:29-0500 [nasa.gov] INFO: Spider closed (finished)
2012-11-12 07:47:29-0500 [scrapy] INFO: Dumping global stats:
{'memusage/max': 104132608, 'memusage/startup': 104132608}

私は立ち往生しています。私が間違っていることに関する提案はありますか?

[編集] 出力ログを追加し、設定のボット名を変更しました。

4

1 に答える 1

1
#pipeline file
from scrapy.contrib.pipeline.images import ImagesPipeline
from scrapy.exceptions import DropItem
from scrapy.http import Request


class PaulsmithPipeline(ImagesPipeline):
   def process_item(self, item, spider):
       return item

def get_media_requests(self,item,info):
    for image_url in item['image_urls']:
         yield Request(image_url)

def item_completed(self,results,item,info):
    image_paths=[x['path'] for ok,x in results if ok]
    if not image_paths:
       raise DropItem("Item contains no images")
    item["image_paths"]=image_paths
    return item 
于 2013-01-17T18:06:34.870 に答える