簡體   English   中英

使用 python 和 selenium 打開 Tor 瀏覽器窗口時,它說缺少 torrc 文件

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

我正在嘗試使用 selenium 在帶有 python 的 ubuntu 上打開一個 Tor 瀏覽器窗口,然后控制它,以便它轉到一個鏈接,輸入一些組合鍵等。當我的代碼打開 Tor 時,它給了我一個彈出窗口“無法啟動 Tor,torrc 文件丟失且無法創建” ,然后繼續打開一個 Tor 窗口,上面寫着“正在等待 Tor 啟動”。 我什至還沒有包含用於在網頁上執行某些操作的其余代碼,因為 tor 甚至不會從一開始就打開。 tor 瀏覽器使用的文件夾和文件以及 /etc/tor 中的 torrc 文件(確實存在!)對所有用戶都具有完全權限。 這是我嘗試運行的簡單代碼,但出現上述錯誤:

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

檢查您是否指向帶有firefox.exe擴展名的正確驅動程序文件

也嘗試更改位置

我正在使用 Windows,這是一個示例:

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

明白你的意思。 我在我的一個項目中嘗試了以下代碼,效果很好。
檢查這是否適合您:

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

參考: Python Selenium 與 TOR 瀏覽器的綁定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM