简体   繁体   English

使用 python 和 selenium 打开 Tor 浏览器窗口时,它说缺少 torrc 文件

[英]when opening a tor browser window using python and selenium, it says torrc file is missing

I am trying to open a tor browser window on ubuntu with python using selenium and then control it so that it goes to a link, puts in some key combinations, etc. when my code goes to open tor, it gives me a pop up saying "Unable to start tor, the torrc file is missing and could not be created" and then proceeds to hand on a tor window saying "waiting for Tor to start".我正在尝试使用 selenium 在带有 python 的 ubuntu 上打开一个 Tor 浏览器窗口,然后控制它,以便它转到一个链接,输入一些组合键等。当我的代码打开 Tor 时,它给了我一个弹出窗口“无法启动 Tor,torrc 文件丢失且无法创建” ,然后继续打开一个 Tor 窗口,上面写着“正在等待 Tor 启动”。 I haven't even included the rest of the code yet for doing some actions on the web page because tor won't even open to begin with.我什至还没有包含用于在网页上执行某些操作的其余代码,因为 tor 甚至不会从一开始就打开。 the folder and file used by the tor browser as well as the torrc file (which does exist!) in /etc/tor all have full permissions for all users. tor 浏览器使用的文件夹和文件以及 /etc/tor 中的 torrc 文件(确实存在!)对所有用户都具有完全权限。 This is the simple code that I am trying to run yet I'm getting the above error:这是我尝试运行的简单代码,但出现上述错误:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.firefox.options import Options
import os


binary = FirefoxBinary('/home/test/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/Browser/firefox')
driver = webdriver.Firefox(firefox_binary = binary)
driver.get("https://www.whatsmyip.org")

Check if you are directing to the right driver file with firefox.exe extension检查您是否指向带有firefox.exe扩展名的正确驱动程序文件

Try changing the location as well也尝试更改位置

I am using windows and here's an example:我正在使用 Windows,这是一个示例:

driver=webdriver.Chrome("D:/OneDrive/Python/Sel_python/drivers/chromedriver.exe")

Got your point.明白你的意思。 I tried the below code in one of my project which worked fine.我在我的一个项目中尝试了以下代码,效果很好。
Check if this works for you:检查这是否适合您:

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

binary = FirefoxBinary(r"C:\Program Files (x86)\TorBrowser\Browser\firefox.exe")
profile = FirefoxProfile(r"C:\Program Files (x86)\TorBrowser\Browser\TorBrowser\Data\Browser\profile.default")

driver = webdriver.Firefox(profile, binary)
driver.get("http://stackoverflow.com")

Reference: Python Selenium binding with TOR browser参考: Python Selenium 与 TOR 浏览器的绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM