2016-12-16 81 views
1

从这个网站 http://www.thedurkweb.com/automated-anonymous-interactions-with-websites-using-python-and-tor/在Python上使用Selenium来操作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,在初始化 restore_signals,start_new_session) 文件 “C:\用户\用户\应用程序数据\本地\程序\ Python的\ Python35-32 \ LIB \ subprocess.py”,线1224,在_execute_child STARTUPINFO ) FileNotFoundError:[WinError 2]系统找不到指定的文件

在处理上述异常,另一个异常:

回溯(最后最近一次调用): 文件 “C:/Users/User/PycharmProjects/LittleBot/Main.py”,第15行,在 browser = Browser('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 timeout = timeout) 文件“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:\用户\用户\应用程序数据\本地\程序\ Python的\ Python35-32 \ LIB \站点包\硒\ webdriver的\ common \ service.py“,第173行,在del self.stop() 文件”C:\ Users \ User \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ site-packages \ selenium \的webdriver \共同\ service.py”,线145,在停止 如果self.process是无: AttributeError的: '服务' 对象没有属性 '过程'

过程,退出代码完成1

我安装了网页上要求的所有库,甚至做到了这一点 - 升级硒的东西,希望摆脱错误。 有什么办法可以解决这个问题吗? 到目前为止,我所知道的是,该程序运行得很好,直到'browser = Browser('firefox',profile_preferences = proxy_settings)'出现。此外Tor浏览器是开放的,所以没有问题。 一直在寻找一个半小时来解决这个问题,并且我尝试了所有与这个主题相关的东西。

回答

0

固定它 pip安装硒== 2.53.6 硒想引入一些壁虎的东西,这是一切都搞乱。 希望这对其他人有用。

+0

“壁虎一些东西”是geckodriver,它现在是在硒3.X的要求推动火狐......类似你如何需要chromedriver开车的Chrome。 –

0

要在Firefox中使用selenium 3.x,您必须安装geckodriver。 的版本的官方网站是在这里:https://github.com/mozilla/geckodriver/releases

从硒python文档

"Selenium requires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver, which needs to be installed before the below examples can be run. Make sure it’s in your PATH, e. g., place it in /usr/bin or /usr/local/bin.

Failure to observe this step will give you an error selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH."

0

如果您正在使用最新的硒和最新的Firefox 1.下载最新geckodriver 2.打开Tor浏览器,隐藏它。 3.运行代码:

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

binary = FirefoxBinary('C:/Program Files(x86)/Mozilla Firefox/firefox.exe') 
profile = webdriver.FirefoxProfile() 

profile.set_preference('network.proxy.type', 1) 
profile.set_preference('network.proxy.socks', '127.0.0.1') 
profile.set_preference('network.proxy.socks_port', 9150) 

driver = webdriver.Firefox(firefox_binary = binary, firefox_profile = profile, executable_path='path/to/geckodriver.exe') 
driver.get('https://check.torproject.org')  
相关问题