title: How to use Tor with Chrome browser through Selenium
body: <p>I'm trying to run my selenium driver on Tor. Note that the script already runs with no errors without Tor.</p>
  
  <p>This is what I've done so far:</p>
  
  <p>1) I called the Tor framework</p>
  
  <pre><code>import socks
  import socket
  from stem.util import term    
  
  
  import stem.process
  
  SOCKS_PORT=7000 
  
  socks.setdefaultproxy(proxy_type=socks.PROXY_TYPE_SOCKS5,
                        addr = "127.0.0.1", 
                        port = SOCKS_PORT)
  socket.socket = socks.socksocket
  
  # Perform DNS resolution through the socket
  def getaddrinfo(*args):   return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
  
  socket.getaddrinfo = getaddrinfo
  
  def print_bootstrap_lines(line):   
      if "Bootstrapped " in line:
        print(term.format(line, term.Color.GREEN))
  
  tor_process = stem.process.launch_tor_with_config(
      tor_cmd = "C:/Users/my-username\Desktop/Tor Browser/Browser/TorBrowser/Tor//tor.exe" ,
      config = { 'SocksPort': str(SOCKS_PORT),},
      init_msg_handler = print_bootstrap_lines,
  )
  </code></pre>
  
  <ol start="2">
  <li><p>After calling the Tor framework which is like a container to my understanding, I then called the Chrome driver:</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.chrome.options import Options
  options = Options()
  options.binary_location = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
  driver = webdriver.Chrome(options=options, executable_path = r'C:\Users\my-username\chromedriver')
  </code></pre></li>
  </ol>
  
  <p>3) At this point I insert the scraping script.</p>
  
  <p>4) Close driver and kill the Tor process:</p>
  
  <pre><code>driver.close()   
  tor_process.kill()
  </code></pre>
  
  <p>The output I get is the following:</p>
  
  <pre><code>Apr 15 14:31:20.000 [notice] Bootstrapped 0%: Starting
  Apr 15 14:31:23.000 [notice] Bootstrapped 10%: Finishing handshake with directory server
  Apr 15 14:31:23.000 [notice] Bootstrapped 80%: Connecting to the Tor network
  Apr 15 14:31:23.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
  Apr 15 14:31:24.000 [notice] Bootstrapped 100%: Done
  Traceback (most recent call last):
  
    File "&lt;ipython-input-2-2b2233fc0ae4&gt;", line 1, in &lt;module&gt;
      runfile('C:/Users/my-username-folder/FireStarter_All_1Step_2.py', wdir='C:/Users/my-username-folder')
  
    File "C:\Users\my-username\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
      execfile(filename, namespace)
  
    File "C:\Users\my-username\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "C:/Users/my-username-folder/FireStarter_All_1Step_2.py", line 94, in &lt;module&gt;
      driver = webdriver.Chrome(options=options, executable_path = r'C:\Users\my-username-folder\chromedriver')
  
    File "C:\Users\my-username\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
      self.service.start()
  
    File "C:\Users\my-username\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\common\service.py", line 104, in start
      raise WebDriverException("Can not connect to the Service %s" % self.path)
  
  WebDriverException: Can not connect to the Service C:\Users\my-username-folder\chromedriver
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Update:
  I am looking to use Tor with Chrome browser.</p>