为何无法通过Python的Selenium同时运行两个独立Tor Browser实例?
同时启动两个Tor Browser Selenium实例失败问题
- 操作背景:在两个独立Python脚本中,通过Selenium启动两个Tor Browser实例;已安装两个全新Tor Browser,分别修改各自安装目录下的
torrc文件,配置了不同端口 - 异常现象:单独运行每个脚本时实例可正常工作,同时启动两个脚本时,第二个实例启动失败,报错信息如下:
Tor exited during startup. This might be due to an error in your torrc file, a bug in Tor or another program on your system, or faulty hardware. Until you fix the underlying problem and restart Tor, Tor Browser will not start.
- 系统环境:全新安装的Windows 11,仅安装Python 3和AnyDesk
- 脚本情况:第一个脚本代码如下,第二个脚本完全复制第一个,仅修改
tor_path为第二个Tor Browser安装目录下的firefox.exe路径
from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC tor_path = r'C:\Tor Browser\Browser\firefox.exe' firefox_options = Options() firefox_options.binary_location = tor_path driver = webdriver.Firefox(options=firefox_options) WebDriverWait(driver, 300).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="connectButton"]')) ) driver.find_element(By.XPATH, value= '//*[@id="connectButton"]').click()
- 排查结果:已通过依次启动并检查端口占用,确认两个实例使用的端口不冲突,但第二个启动的脚本无日志输出,甚至未尝试连接Tor网络
内容的提问来源于stack exchange,提问作者anjoyer
相关产品推荐
相关产品推荐

