2

我有几只蜘蛛需要爬。我正在使用带有默认设置的scrapyd。我设法用 scrapyd 界面安排我的工作。在这一点上一切都很好,除了工作没有结束。每次我检查时,我发现有 16 个(4 个作业 / 4 个 cpus)作业正在运行,并且所有其他作业都处于挂起状态,除非我关闭了 scrapy。

我还检查了日志,它说:

2013-09-22 12:20:55+0000 [spider1] INFO: Dumping Scrapy stats:
    {
     'downloader/exception_count': 1,
     'downloader/exception_type_count/scrapy.exceptions.IgnoreRequest': 1,
     'downloader/request_bytes': 244,
     'downloader/request_count': 1,
     'downloader/request_method_count/GET': 1,
     'downloader/response_bytes': 7886,
     'downloader/response_count': 1,
     'downloader/response_status_count/200': 1,
     'finish_reason': 'finished',
     'finish_time': datetime.datetime(2013, 9, 22, 12, 20, 55, 635611),
     'log_count/DEBUG': 7,
     'log_count/INFO': 3,
     'request_depth_max': 1,
     'response_received_count': 1,
     'scheduler/dequeued': 2,
     'scheduler/dequeued/memory': 2,
     'scheduler/enqueued': 2,
     'scheduler/enqueued/memory': 2,
     'start_time': datetime.datetime(2013, 9, 22, 12, 20, 55, 270275)}
2013-09-22 12:20:55+0000 [spider1] INFO: Spider closed (finished)

你如何使用 scrapyd 抓取数百个蜘蛛?

编辑:

scrapy.cfg:

[settings]
default = myproject.scrapers.settings

[deploy]
url = http://localhost:6800/
project = myproject
version = GIT

[scrapyd]
eggs_dir    = scrapy_dir/eggs
logs_dir    = scrapy_dir/logs
items_dir   = scrapy_dir/items
dbs_dir     = scrapy_dir/dbs

scrapy settings.py

import os
from django.conf import settings

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

BOT_NAME = 'scrapers'

SPIDER_MODULES = ['myproject.scrapers.spiders']

DOWNLOADER_MIDDLEWARES = {
    'myproject.scrapers.middlewares.IgnoreDownloaderMiddleware': 50,
}

ITEM_PIPELINES = [
    'myproject.scrapers.pipelines.CheckPipeline',
    'myproject.scrapers.pipelines.CleanPipeline',
    'myproject.contrib.pipeline.images.ImagesPipeline',
    'myproject.scrapers.pipelines.SerializePipeline',
    'myproject.scrapers.pipelines.StatsCollectionPipeline',
]    

DOWNLOAD_DELAY = 0.25

path_to_phatomjs = '/home/user/workspace/phantomjs-1.9.1-linux-x86_64/bin/phantomjs'

IMAGES_STORE = settings.MEDIA_ROOT + '/' + settings.IMAGES_STORE
IMAGES_THUMBS = {
    'small': (70, 70),
    'big': (270, 270),
}
4

1 回答 1

0

昨天,我一找到问题的根源就尝试发布此答案,但是我的帐户出了点问题。

问题来自 PhantomJs 驱动程序,它阻止了 scrapyd 完成工作。

起初我是用删除功能退出驱动程序:

def __del__(self):
    self.driver.quit()
    ...

现在我创建了一个函数quit_driver,并将它与spider_closed 信号挂钩。

@classmethod
def from_crawler(cls, crawler):
    temp = cls(crawler.stats)
    crawler.signals.connect(temp.quit_driver, signal=signals.spider_closed)
    return temp
于 2013-09-24T16:03:02.120 回答