账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    selenium如何设置代理ip?
    83
    0

    爬虫萌新一枚,最近在用selenium作动态页面的处理,但是时间久了会遇到被禁止访问的情况,在网上找了一些设置selenium代理的资料,每个都尝试了,但是还是不行,网页都打不开。
    方法一:

    options = webdriver.FirefoxOptions()  
    options.add_argument('--proxy-server=xxxx:xxxx')

    方法二:

    proxy = Proxy(  
        {  
            'proxyType': ProxyType.MANUAL,  
            'httpProxy': 'https://58.218.92.89:8272'  
      }  
    )  
      
    driver = webdriver.Firefox(firefox_options=options, proxy=proxy)

    方法三:

    profile = webdriver.FirefoxProfile()  
      
    profile.set_preference('network.proxy.type', 1)  
    profile.set_preference('network.proxy.http', '58.218.92.159')  
    profile.set_preference('network.proxy.http_port', 5057)  # int  
    profile.update_preferences()  
    driver = webdriver.Firefox(firefox_profile=profile)

    方法四:

    proxy = Proxy(  
        {  
            'proxyType': ProxyType.MANUAL,  
            'httpProxy': '58.218.200.253:5762' # 代理ip和端口  
      }  
    )  
    # 新建一个“期望技能”,哈哈  
    desired\_capabilities = DesiredCapabilities.CHROME.copy()  
    # 把代理ip加入到技能中  
    proxy.add_to_capabilities(desired_capabilities)  
    driver = webdriver.Chrome(desired_capabilities=desired_capabilities)

    以上方法都有实践和测试过,但是都打不开网页,请路过的大佬指点一下,如何设置selenium的代理ip

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部