हां, यह संभव है।
मैंने अपने स्पाइडर क्लास में एक असफल_रल्स सूची जोड़ा और प्रतिक्रिया की स्थिति 404 थी (इसे अन्य त्रुटि स्थितियों को कवर करने के लिए विस्तारित करने की आवश्यकता होगी) में यूआरएल संलग्न किया गया था।
फिर मैंने एक हैंडल जोड़ा जो सूची को एक स्ट्रिंग में शामिल करता है और स्पाइडर बंद होने पर इसे आंकड़ों में जोड़ता है।
आपकी टिप्पणियों के आधार पर, ट्विस्ट त्रुटियों को ट्रैक करना संभव है।
from scrapy.spider import BaseSpider
from scrapy.xlib.pydispatch import dispatcher
from scrapy import signals
class MySpider(BaseSpider):
handle_httpstatus_list = [404]
name = "myspider"
allowed_domains = ["example.com"]
start_urls = [
'http://www.example.com/thisurlexists.html',
'http://www.example.com/thisurldoesnotexist.html',
'http://www.example.com/neitherdoesthisone.html'
]
def __init__(self, category=None):
self.failed_urls = []
def parse(self, response):
if response.status == 404:
self.crawler.stats.inc_value('failed_url_count')
self.failed_urls.append(response.url)
def handle_spider_closed(spider, reason):
self.crawler.stats.set_value('failed_urls', ','.join(spider.failed_urls))
def process_exception(self, response, exception, spider):
ex_class = "%s.%s" % (exception.__class__.__module__, exception.__class__.__name__)
self.crawler.stats.inc_value('downloader/exception_count', spider=spider)
self.crawler.stats.inc_value('downloader/exception_type_count/%s' % ex_class, spider=spider)
dispatcher.connect(handle_spider_closed, signals.spider_closed)
आउटपुट (डाउनलोडर/exception_count * आंकड़े केवल दिखाई देगा, यदि अपवाद वास्तव में फेंक दिया जाता है - मैं उन्हें मकड़ी को चलाने के लिए कोशिश कर रहा द्वारा नकली के बाद मैं अपने वायरलेस एडाप्टर को बंद कर दिया था):
2012-12-10 11:15:26+0000 [myspider] INFO: Dumping Scrapy stats:
{'downloader/exception_count': 15,
'downloader/exception_type_count/twisted.internet.error.DNSLookupError': 15,
'downloader/request_bytes': 717,
'downloader/request_count': 3,
'downloader/request_method_count/GET': 3,
'downloader/response_bytes': 15209,
'downloader/response_count': 3,
'downloader/response_status_count/200': 1,
'downloader/response_status_count/404': 2,
'failed_url_count': 2,
'failed_urls': 'http://www.example.com/thisurldoesnotexist.html, http://www.example.com/neitherdoesthisone.html'
'finish_reason': 'finished',
'finish_time': datetime.datetime(2012, 12, 10, 11, 15, 26, 874000),
'log_count/DEBUG': 9,
'log_count/ERROR': 2,
'log_count/INFO': 4,
'response_received_count': 3,
'scheduler/dequeued': 3,
'scheduler/dequeued/memory': 3,
'scheduler/enqueued': 3,
'scheduler/enqueued/memory': 3,
'spider_exceptions/NameError': 2,
'start_time': datetime.datetime(2012, 12, 10, 11, 15, 26, 560000)}
यह अब काम नहीं करता है। 'अपवाद। नाम त्रुटि: वैश्विक नाम 'स्वयं' परिभाषित नहीं किया गया है 'त्रुटि होती है। 'बेसस्पीडर' अब सिर्फ 'स्पाइडर' है http://doc.scrapy.org/en/0.24/news.html?हाइलाइट = बेसस्पीडर # आईडी 2 https://github.com/scrapy/dirbot/blob/master/dirbot/spiders/dmoz.py लेकिन मुझे अभी तक आपका कोड काम करने के लिए फिक्स नहीं मिल रहा है। – Mikeumus