Esempio n. 1
0
 def _build(self, config):
     try:
         self.name = config['name']
         Logger.register(self.name)
         Logger.load()
         self.logger = Logger(self.name)
         self.debug = config.get('debug', True)
         self.logger.info(self.name, 'Start building...')
         self.scraper = Scraper.get(config['scraper']['name'])(self)
         if 'args' in config['scraper']:
             self.scraper.setargs(config['scraper']['args'])
         self.frontier = Frontier.get(config['frontier']['name'])(self)
         if 'args' in config['frontier']:
             self.frontier.setargs(config['frontier']['args'])
         for each in config['handlers']:
             handler = Handler.get(each['name'])(self)
             if 'args' in each:
                 handler.setargs(each['args'])
             self.handlers.append(handler)
         self.logger.info(self.name, 'Build successful!')
     except KeyError as e:
         raise PyCrawlerException('Key \''+e.args[0]+'\' missing in config dict')
Esempio n. 2
0
 def test_getScraper(self):
     self.assertRaises(ScraperException, Scraper.get, 'None')
     self.assertEqual(DefaultScraper, Scraper.get('DefaultScraper'))
     self.assertIsInstance(Scraper.get('DefaultScraper')(SpiderTest('testspider')), DefaultScraper)