def load_firefox(config):
"""Start Firefox webdriver with the given configuration.
Args:
config (dict): The configuration loaded previously in Cabu.
Returns:
webdriver (selenium.webdriver): An instance of Firefox webdriver.
"""
binary = None
profile = webdriver.FirefoxProfile()
if os.environ.get('HTTPS_PROXY') or os.environ.get('HTTP_PROXY'):
proxy_address = os.environ.get('HTTPS_PROXY', os.environ.get('HTTP_PROXY'))
proxy_port = re.search('\:([0-9]+)$', proxy_address).group(1)
profile.set_preference('network.proxy.type', 1)
profile.set_preference(
'network.proxy.http',
proxy_address
)
profile.set_preference('network.proxy.http_port', proxy_port)
profile.update_preferences()
if 'HEADERS' in config and config['HEADERS']:
profile = Headers(config).set_headers(profile)
if config['DRIVER_BINARY_PATH']:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(config['DRIVER_BINARY_PATH'])
return webdriver.Firefox(firefox_binary=binary, firefox_profile=profile)
评论列表
文章目录