首页 > 解决方案 > 每次我尝试使用 selenium 启动 Tor 时,Python 都会崩溃:请不要删除我的问题,其他问题只有 C# 中的答案

问题描述

每次我想运行我的 Program Tor 时都会崩溃。该代码没有错误。路径都是正确的。这是我的代码:

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()


firefox_options = webdriver.FirefoxOptions()
firefox_options.binary_location = r'C:/Users/Seya Fässler/Desktop/Tor Browser/Browser/firefox.exe'
driver = webdriver.Firefox(firefox_profile= profile, options = firefox_options, executable_path=r'C:/Users/Seya Fässler/Webdrivers/geckodriver.exe')
driver.get("https://www.apple.com")

之后,它会显示此警报:

Tor警报

当我按 OK 时,它会打开此窗口并且我无法复制日志,因为它有 0 行。

Tor 警报 2

我使用 Windows 10,作为我使用 anaconda 的环境,tor 浏览器是最新版本(9.5.3),我使用 Python 3.8.3。 请不要因为重复而删除我的问题,另一个问题有答案但仅在 C# 中,它不适用于 python! 谢谢!

标签: pythonseleniumselenium-webdriver

解决方案


推荐阅读