# browser module defines functions for creating selenium webdriver # objects. The way this works is selenium is a third-party library # that gives a common interface for interacting with web browsers, # i.e. chrome, firefox, internet explorer, and even a pseudo-browser. # # This library (selenium) creates a web browser process # (chrome will actually fire up for you to see) and gives you # a webdriver object interface to programmatically control the browser. # You can do things like click on links, extract information from the # page, pass control to a user... the limit is your imagination. import selenium import selenium.webdriver import logging from . import config # This function has a parameter (driver) that passes in a value. In this case, # this driver variable defaults to the string 'chrome'. The code can call # create_webdriver() which is the same as create_webdriver('chrome') but # can alternatively call create_webdriver('firefox') and get different # functionality. def create_webdriver(driver='chrome'): if driver == 'chrome': return create_webdriver_chrome() elif driver == 'firefox': return create_webdriver_firefox() def create_webdriver_firefox(): pass def create_webdriver_chrome(): opt = selenium.webdriver.chrome.options.Options() opt.add_argument('--user-agent=' + config.obj.WEBDRIVER_USER_AGENT) driver = selenium.webdriver.Chrome(chrome_options = opt) return driver