I’ve been trying to configure Selenium and Chrome to use Tor as proxy and constantly getting error messages like the following:
WebDriverException: Message: invalid argument: cannot parse capability: proxy
from invalid argument: Specifying ‘socksProxy’ requires an integer for ‘socksVersion’
(Driver info: chromedriver=2.44.609545 (c2f88692e98ce7233d2df7c724465ecacfe74df5),platform=Mac OS X 10.14.0 x86_64)
In the end I have to use HTTP proxy instead of SOCKS.
Install and start Tor:
brew install tor brew services start tor
Install privoxy:
brew install privoxy
Configure privoxy (vi /usr/local/etc/privoxy/config) to chain it with Tor:
forward-socks5t / 127.0.0.1:9050 .
Start privoxy by default on port 8118:
brew services start privoxy
Check if your traffic is proxied:
from selenium.webdriver.common.proxy import Proxy, ProxyType from selenium import webdriver prox = Proxy() prox.proxy_type = ProxyType.MANUAL prox.http_proxy = "http://localhost:8118" prox.ssl_proxy = "http://localhost:8118" capabilities = webdriver.DesiredCapabilities.CHROME prox.add_to_capabilities(capabilities) options = webdriver.ChromeOptions() options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' # options.add_argument('headless') # set the window size options.add_argument('window-size=1881x1280') # initialize the driver driver = webdriver.Chrome(options=options, desired_capabilities=capabilities) driver.get('http://httpbin.org/ip')
Now you should see a different IP than your real one.
Comments