简体   繁体   English

在Python中使用Selenium访问Tor

[英]Accessing Tor with Selenium in Python

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: 我正在尝试使用python中的selenium访问tor浏览器,但是当我的程序打开Tor时,Tor会给我一条错误消息:

Tor failed to start.  

Python then gives the following error message: Python然后给出以下错误消息:

selenium.common.exceptions.WebDriverException: Message: permission denied

My code is the following: 我的代码如下:

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! 任何有关这方面的帮助将不胜感激!

To access the Tor browser using Selenium through Python you can use the following solution: 要通过Python使用Selenium访问Tor浏览器,您可以使用以下解决方案:

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

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

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