mirror of https://github.com/scrapy/scrapy.git
moved log method to BaseSpider, moved adapt_feed doc to docstring
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40395
This commit is contained in:
parent
d4040d73d9
commit
5ccd4df0cd
|
|
@ -3,7 +3,6 @@ This module contains some basic spiders for scraping websites (CrawlSpider)
|
|||
and XML feeds (XMLFeedSpider).
|
||||
"""
|
||||
|
||||
from scrapy import log
|
||||
from scrapy.conf import settings
|
||||
from scrapy.http import Request
|
||||
from scrapy.spider import BaseSpider
|
||||
|
|
@ -21,14 +20,10 @@ def _set_guid(spider, item):
|
|||
"""
|
||||
raise NotConfigured('You must define a set_guid method in order to scrape items.')
|
||||
|
||||
def _log(spider, message, level=log.DEBUG):
|
||||
log.msg(message, domain=spider.domain_name, level=level)
|
||||
|
||||
class CrawlSpider(BaseSpider):
|
||||
"""
|
||||
This class works as a base class for spiders that crawl over websites
|
||||
"""
|
||||
log = _log
|
||||
set_guid = _set_guid
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -108,7 +103,6 @@ class XMLFeedSpider(BaseSpider):
|
|||
You can choose whether to parse the file using the iternodes tool,
|
||||
or not using it (which just splits the tags using xpath)
|
||||
"""
|
||||
log = _log
|
||||
set_guid = _set_guid
|
||||
iternodes = True
|
||||
itertag = 'item'
|
||||
|
|
@ -139,15 +133,15 @@ class CSVFeedSpider(BaseSpider):
|
|||
You can set some options regarding the CSV file, such as the delimiter
|
||||
and the file's headers.
|
||||
"""
|
||||
log = _log
|
||||
set_guid = _set_guid
|
||||
delimiter = None # When this is None, python's csv module's default delimiter is used
|
||||
headers = None
|
||||
|
||||
# You can override this function in order to make any changes you want to
|
||||
# into the feed before parsing it.
|
||||
# This function may return either a response or a string.
|
||||
def adapt_feed(self, response):
|
||||
"""You can override this function in order to make any changes you want
|
||||
to into the feed before parsing it. This function may return either a
|
||||
response or a string. """
|
||||
|
||||
return response
|
||||
|
||||
def parse_row_wrapper(self, response, row):
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ Base class for scrapy spiders
|
|||
from zope.interface import Interface, Attribute, invariant, implements
|
||||
from twisted.plugin import IPlugin
|
||||
|
||||
from scrapy import log
|
||||
from scrapy.core.exceptions import UsageError
|
||||
|
||||
def _valid_start_urls(obj):
|
||||
|
|
@ -87,3 +88,9 @@ class BaseSpider(object):
|
|||
implements(ISpider)
|
||||
domain_name = None
|
||||
extra_domain_names = []
|
||||
|
||||
def log(self, message, level=log.DEBUG):
|
||||
"""Log the given messages at the given log level. Always use this
|
||||
method to send log messages from your spider
|
||||
"""
|
||||
log.msg(message, domain=self.domain_name, level=level)
|
||||
|
|
|
|||
Loading…
Reference in New Issue