我在通过Selenium启动Tor时遇到问题,找到了“解决方案”,但出现错误

时间:2020-08-01 19:04:27

标签: python selenium selenium-webdriver

我为此question找到了解决方案。 这是答案的我编辑过的版本(路径正确):

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os

torexe = os.popen(r'C:/Users/Seya Fässler/Desktop/Tor Browser/Browser/TorBrowser/Tor/tor.exe')
profile = FirefoxProfile(r'C:/Users/Seya Fässler/Desktop/Tor Browser/Browser/TorBrowser/Data/Browser/profile.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:/Users/Seya Fässler/Webdrivers/geckodriver.exe')
driver.get("http://check.torproject.org")

我认为路径是正确的。我启动它后,它会显示一个Windows,并且警报器无法启动。这是显示的错误:

Traceback (most recent call last):
  File "c:/Users/Seya Fässler/Desktop/Python/tor-python.py/test8.py", line 12, in <module>
    driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:/Users/Seya Fässler/Webdrivers/geckodriver.exe')
  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session       
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response   
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Zugriff verweigert (os error 5)

我使用Windows 10和Python 3.8.4。谢谢!

0 个答案:

没有答案