Firefox 67+中具有代理的硒

时间:2019-06-28 15:43:01

标签: python-3.x selenium proxy

我已经尝试了几种设置的变体,包括firefox配置文件设置以及下面显示的当前方法,但是Seleniun仍然忽略代理设置并直接连接。我似乎找不到在最新的Firefox中实际可用的任何说明或教程。我的代码有什么问题?

        logger.info("Using Proxy Options")
        # Selenium Firefox Profile Path
        profile_path = ffprofile_path
        extension_dir = os.path.join(ffprofile_path, "extensions")
        profile = webdriver.FirefoxProfile(profile_path)
        user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
        http_proxy = "my_proxy_ip:1027"
        # # Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
        # profile.set_preference("network.proxy.type", 0)
        # profile.set_preference("network.proxy.http", proxy_ip)
        # profile.set_preference("network.proxy.http_port", int(proxy_port))
        # profile.set_preference("general.useragent.override", user_agent)
        # profile.update_preferences()
        proxy = Proxy({
            'proxyType': ProxyType.MANUAL,
            'httpProxy': http_proxy,
            'ftpProxy': http_proxy,
            'sslProxy': http_proxy,
            'noProxy': ''  # set this value as desired
        })
        ##########################################################
        ##########################################
        cap["firefox_profile"] = profile.encoded
        driver = webdriver.Firefox(
            firefox_profile=profile,
            capabilities=cap,
            options=opts,
            executable_path=gecko_path,
            proxy=proxy
        )
    # Test to see if Proxy is Working
    logger.info("Testing Proxy")
    driver.get("https://www.actual_url_redacted_")
    show_ip = driver.page_source
    logger.info('IP Shown: ' + str(show_ip))

0 个答案:

没有答案