Coverage for scrapy/utils/spider : 76%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
"""Return an iterator over all spider classes defined in the given module that can be instantiated (ie. which have name) """ # this needs to be imported here until get rid of the spider manager # singleton in scrapy.spider.spiders
issubclass(obj, BaseSpider) and \ obj.__module__ == module.__name__ and \ getattr(obj, 'name', None):
log_none=False, log_multiple=False, **spider_kwargs): """Create a spider to handle the given Request.
This will look for the spiders that can handle the given request (using the spider manager) and return a (new) Spider if (and only if) there is only one Spider able to handle the Request.
If multiple spiders (or no spider) are found, it will return the default_spider passed. It can optionally log if multiple or no spiders are found. """ snames = spidermanager.find_by_request(request) if len(snames) == 1: return spidermanager.create(snames[0], **spider_kwargs) if len(snames) > 1 and log_multiple: log.msg('More than one spider can handle: %s - %s' % \ (request, ", ".join(snames)), log.ERROR) if len(snames) == 0 and log_none: log.msg('Unable to find spider that handles: %s' % request, log.ERROR) return default_spider
|