Python中Selenium调用FirefoxDriver出现FileNotFoundError问题求助
解决Selenium调用Tor Firefox Profile时的文件未找到错误
问题根源
Tor浏览器的默认profile目录可能未生成user.js文件,或是Selenium复制profile时遇到权限限制、版本不兼容,导致无法创建/读取该文件。
解决步骤
手动补全缺失的
user.js文件
找到Tor的profile目录C:\Program Files\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default,在该目录下新建一个空白的user.js文件(注意要去掉.txt后缀)。改用Selenium新版API加载profile
旧版FirefoxProfile已被弃用,推荐使用Options类来加载profile,修改代码如下:from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() options.profile = r'C:\Program Files\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default' driver = webdriver.Firefox(options=options, executable_path=r'C:\WebDrivers\geckodriver.exe')检查目录读写权限
右键Tor的profile目录,选择「属性」→「安全」,确认当前登录用户拥有该目录的读写权限,避免Selenium复制文件时被系统拦截。匹配geckodriver与Tor Firefox版本
打开Tor浏览器,通过「帮助」→「关于Tor浏览器」查看内置Firefox的版本,下载对应版本的geckodriver,确保两者版本兼容。
内容的提问来源于stack exchange,提问作者OlegXio
相关产品推荐
相关产品推荐

