本文介绍了在Python中使用Selenium访问Tor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试了多种解决方案,但是到目前为止还没有任何运气.我正在尝试使用python中的硒访问Tor浏览器,但是当我的程序打开Tor时,Tor给我一条错误消息,提示:
I've tried a multitude of solutions to this, but so far haven't had any luck. I'm trying to access the tor browser using selenium in python, but when my program opens up Tor, Tor gives me an error message saying:
Tor failed to start.
Python然后给出以下错误消息:
Python then gives the following error message:
selenium.common.exceptions.WebDriverException: Message: permission denied
我的代码如下:
binary = FirefoxBinary(r"C:\\Users\\User\\Desktop\\Tor Browser\\Browser\\firefox.exe")
profile = FirefoxProfile(r"C:\\Users\\User\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default")
driver = webdriver.Firefox(firefox_binary=binary)
driver = webdriver.Firefox(firefox_profile= profile, firefox_binary= binary, executable_path = r"C:\\Users\\User\\Desktop\\geckodriver.exe")
driver.profile.set_preference('network.proxy.type', 1)
driver.profile.set_preference('network.proxy.socks', '127.0.0.1')
driver.profile.set_preference('network.proxy.socks_port', 9150)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver.get("http://yahoo.com")
在此方面的任何帮助将不胜感激!
Any help on this would be greatly appreciated!
推荐答案
要通过 Python 使用 Selenium 访问 Tor 浏览器,可以使用以下解决方案:
To access the Tor browser using Selenium through Python you can use the following solution:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
torexe = os.popen(r'C:\Users\AtechM_03\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile = FirefoxProfile(r'C:\Users\AtechM_03\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()
driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("http://check.torproject.org")
这篇关于在Python中使用Selenium访问Tor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!