scrapy 2.3 从蜘蛛记录
Scrapy提供了 logger 在每个蜘蛛实例中,可以这样访问和使用:
import scrapy
class MySpider(scrapy.Spider):
name = 'myspider'
start_urls = ['https://scrapinghub.com']
def parse(self, response):
self.logger.info('Parse function called on %s', response.url)
这个记录器是使用蜘蛛的名称创建的,但是您可以使用任何您想要的自定义Python记录器。例如::
import logging
import scrapy
logger = logging.getLogger('mycustomlogger')
class MySpider(scrapy.Spider):
name = 'myspider'
start_urls = ['https://scrapinghub.com']
def parse(self, response):
logger.info('Parse function called on %s', response.url)