How can I set socks5 proxy for selenium webdriver? Python

旧街凉风 提交于 2020-12-04 02:25:34

问题


I really can’t to set socks5 proxy(http too...) for my chrome webdriver in selenium for python. I tried many different ways... But I think I do something bad.

Example 1:

self.options.add_argument('--proxy-server=http://'+proxy)

Example 2:

webdriver.DesiredCapabilities.CHROME['proxy'] = {
        "socksProxy": proxy,
        "ftpProxy": proxy,
        "sslProxy": proxy,
        "noProxy": None,
        "proxyType": "MANUAL",
        "class": "org.openqa.selenium.Proxy",
        "autodetect": False
    }

Please describe fully the working example of setting up socks5 proxy on Selenium for Python and Chrome webdriver, with an example of proxy string formats (maybe i am doing something mistakes here ...).

PS Two problems which I get:

  1. Just staying old IP address.
  2. No internet connection in chrome web driver.

回答1:


Chrome do not allow proxy with auth. I am not shure but after read so many informations I think so.... Only one way is working for me - to use proxy socks5 without auth by login and password.

 options = webdriver.ChromeOptions()
 proxy = '12.12.421.125:1949'   
 options.add_argument('--proxy-server=socks5://' + proxy)
 driver = webdriver.Chrome(options=self.options)



回答2:


For FireFox's geckodriver if you just want to set socks5 host / socks5 proxy :-

form selenium import webdriver

profile = webdriver.FirefoxProfile()

# Socks5 Host SetUp:-
myProxy = "198.199.101.152:8388"
ip, port = myProxy.split(':')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', ip)
profile.set_preference('network.proxy.socks_port', int(port))

driver = webdriver.Firefox(firefox_profile=profile)


来源:https://stackoverflow.com/questions/53082267/how-can-i-set-socks5-proxy-for-selenium-webdriver-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!