drivers.py 文件源码

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

项目:cabu 作者: thylong 项目源码 文件源码
def load_phantomjs(config):
    """Start PhantomJS webdriver with the given configuration.

    Args:
        config (dict): The configuration loaded previously in Cabu.

    Returns:
        webdriver (selenium.webdriver): An instance of phantomJS webdriver.

    """
    dcap = dict(DesiredCapabilities.PHANTOMJS)
    service_args = [
        '--ignore-ssl-errors=true',
        '--ssl-protocol=any',
        '--web-security=false'
    ]

    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_ip = re.search('http\:\/\/(.*)$', proxy_address).group(1)
        service_args.append('--proxy=%s' % proxy_ip)
        service_args.append('--proxy-type=http')

    if 'HEADERS' in config and config['HEADERS']:
        dcap = Headers(config).set_headers(dcap)

    return webdriver.PhantomJS(
        desired_capabilities=dcap,
        service_args=service_args,
        service_log_path=os.path.devnull
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号