NoName Johnson
NoName Johnson

Reputation: 21

Using Selenium on Python to operate Tor. Doesn't work for unknown reasons

From this website http://www.thedurkweb.com/automated-anonymous-interactions-with-websites-using-python-and-tor/

I did the following code

enter code here

import stem.process
from stem import Signal
from stem.control import Controller
from splinter import Browser

proxyIP = "127.0.0.1"
proxyPort = 9150

proxy_settings = {"network.proxy.type": 1,
              "network.proxy.ssl": proxyIP,
              "network.proxy.ssl_port": proxyPort,
              "network.proxy.socks": proxyIP,
              "network.proxy.socks_port": proxyPort,
              "network.proxy.socks_remote_dns": True,
              "network.proxy.ftp": proxyIP,
              "network.proxy.ftp_port": proxyPort
              }
browser = Browser('firefox', profile_preferences=proxy_settings)
browser.visit("http://www.icanhazip.com")

Didn't work. Just get these errors

Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start stdout=self.log_file, stderr=self.log_file) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in init restore_signals, start_new_session) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/User/PycharmProjects/LittleBot/Main.py", line 15, in browser = Browser('firefox', profile_preferences=proxy_settings) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\splinter\browser.py", line 63, in Browser return driver(*args, **kwargs) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\splinter\driver\webdriver\firefox.py", line 48, in init timeout=timeout) File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 140, in init self.service.start() File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Exception ignored in: > Traceback (most recent call last): File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 173, in del self.stop() File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 145, in stop if self.process is None: AttributeError: 'Service' object has no attribute 'process'

Process finished with exit code 1

I installed all the libraries requested on the webpage, and even did that --upgrade selenium thing in hopes of getting rid of the errors. Is there any way to solve this? So far all I know is that the program runs just fine until the 'browser = Browser('firefox', profile_preferences=proxy_settings)' occurs. Also the Tor browser is open, so no problems there. Been searching for an hour and a half for a solution to this, and I've tried everything that relates to this subject.

Upvotes: 2

Views: 1511

Answers (3)

NoName Johnson
NoName Johnson

Reputation: 21

Fixed it

pip install selenium==2.53.6

Selenium wants to introduce some gecko thing and that's messing with everything. Hope this is of use to other people.

Upvotes: 0

AK9309
AK9309

Reputation: 791

If you are using latest selenium and latest Firefox 1. Download latest geckodriver 2. Open tor browser, hide it. 3. run code:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefoc.firefox_profile import FirefoxProfile

binary = FirefoxBinary('C:/Program Files(x86)/Mozilla Firefox/firefox.exe')
profile = webdriver.FirefoxProfile()

profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9150)

driver = webdriver.Firefox(firefox_binary = binary, firefox_profile = profile, executable_path='path/to/geckodriver.exe')
driver.get('https://check.torproject.org')    

Upvotes: -2

Corey Goldberg
Corey Goldberg

Reputation: 60614

To use selenium 3.x with Firefox, you must install geckodriver. The official site for releases is here: https://github.com/mozilla/geckodriver/releases

from the selenium python docs:

"Selenium requires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver, which needs to be installed before the below examples can be run. Make sure it’s in your PATH, e. g., place it in /usr/bin or /usr/local/bin.

Failure to observe this step will give you an error selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH."

Upvotes: -1

Related Questions