Skip to main content
 首页 » 编程设计

python之在 Python 上使用 Selenium 来操作 Tor。由于未知原因不起作用

2025年05月04日7bhlsheji

从这个网站 http://www.thedurkweb.com/automated-anonymous-interactions-with-websites-using-python-and-tor/

我做了以下代码

enter code here 
 
import stem.process 
from stem import Signal 
from stem.control import Controller 
from splinter import Browser 
 
proxyIP = "127.0.0.1" 
proxyPort = 9150 
 
proxy_settings = {"network.proxy.type": 1, 
              "network.proxy.ssl": proxyIP, 
              "network.proxy.ssl_port": proxyPort, 
              "network.proxy.socks": proxyIP, 
              "network.proxy.socks_port": proxyPort, 
              "network.proxy.socks_remote_dns": True, 
              "network.proxy.ftp": proxyIP, 
              "network.proxy.ftp_port": proxyPort 
              } 
browser = Browser('firefox', profile_preferences=proxy_settings) 
browser.visit("http://www.icanhazip.com") 

没用。只是得到这些错误

追溯(最近的调用最后): 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py”,第 74 行,在开始 stdout=self.log_file, stderr=self.log_file) 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py”,第 947 行,在 init 中 restore_signals, start_new_session) 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py”,第 1224 行,在 _execute_child 中 启动信息) FileNotFoundError: [WinError 2] 系统找不到指定的文件

在处理上述异常的过程中,又发生了一个异常:

追溯(最近的调用最后): 文件“C:/Users/User/PycharmProjects/LittleBot/Main.py”,第 15 行,位于 浏览器 = 浏览器('firefox',profile_preferences = proxy_settings) 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\splinter\browser.py”,第 63 行,在浏览器中 返回驱动程序(*args,**kwargs) 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\splinter\driver\webdriver\firefox.py”,第 48 行,init 超时=超时) 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py”,第 140 行,在 init self.service.start() 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py”,第 81 行,在开始 os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException:消息:'geckodriver' 可执行文件需要在 PATH 中。

异常被忽略:> 追溯(最近一次通话): 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py”,第 173 行,del self 停止() 文件“C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py”,第 145 行,停止 如果 self.process 为无: AttributeError: 'Service' 对象没有属性 'process'

进程结束,退出代码为 1

我安装了网页上请求的所有库,甚至做了 --upgrade selenium 的事情,希望能消除错误。 有什么办法可以解决这个问题吗? 到目前为止,我所知道的是程序运行正常,直到出现“browser = Browser('firefox', profile_preferences=proxy_settings)”。 Tor 浏览器也已打开,所以没有问题。 一直在寻找一个半小时的解决方案,我已经尝试了与该主题相关的所有内容。

请您参考如下方法:

修复了

pip install selenium==2.53.6 

Selenium 想要引入一些 gecko 东西,这会把一切都搞乱。 希望这对其他人有用。