drivers.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:cabu 作者: thylong 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号