Home | History | Annotate | Download | only in scrapers
      1 #!/usr/bin/env python
      2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 """Selects the appropriate scraper for a given browser and version."""
      7 
      8 import types
      9 
     10 # TODO(jhaas): unify all optional scraper parameters into kwargs
     11 
     12 def GetScraper(browser):
     13   """Given a browser and an optional version, returns the scraper module.
     14 
     15   Args:
     16     browser: either a string (browser name) or a tuple (name, version)
     17 
     18   Returns:
     19     module
     20   """
     21 
     22   if type(browser) == types.StringType: browser = (browser, None)
     23 
     24   package = __import__(browser[0], globals(), locals(), [''])
     25   module = package.GetScraper(browser[1])
     26   if browser[1] is not None: module.version = browser[1]
     27 
     28   return module
     29 
     30 
     31 # if invoked rather than imported, do some tests
     32 if __name__ == "__main__":
     33   print GetScraper("IE")
     34