带有TOR浏览器的Python Selenium绑定 [英] Python Selenium binding with TOR browser

查看:127
本文介绍了带有TOR浏览器的Python Selenium绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此进行了研究,但得到了解决方案:

I researched on it but I get that solution:

from selenium import webdriver
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', 9050)
driver = webdriver.Firefox(profile)
driver.get('http://estoeslapollaconcebol.la')

它给出了该错误:

无法加载配置文件.个人资料目录: C:\ Users \ HPPAV1〜1 \ AppData \ Local \ Temp \ tmppcuwx3xd Firefox输出: 没有

Can't load the profile. Profile Dir: C:\Users\HPPAV1~1\AppData\Local\Temp\tmppcuwx3xd Firefox output: None

当我尝试该解决方案时.

When I try that solution.

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
profile=webdriver.FirefoxProfile('C:\\Users\\HP PAV 15\\Desktop\\Tor     Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default\\')
binary =FirefoxBinary('C:\\Users\\HP PAV 15\\Desktop\\Tor Browser\\Browser\\firefox')
#browser = binary.launch_browser(profile)
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)
browser=webdriver.Firefox( binary, profile)
browser.get("http://yahoo.com")
browser.save_screenshot("/Users/admin/Pictures/screenshot.png")
browser.close()

它给了我以下错误:

回溯(最近通话最近):文件 "C:/Python34/torfirstscript.py",第10行,在 browser = webdriver.Firefox(二进制,配置文件)文件"C:\ Python34 \ lib \ site-packages \ selenium-2.43.0-py3.4.egg \ selenium \ webdriver \ firefox \ webdriver.py", 第46行,在 init 中 self.NATIVE_EVENTS_ALLOWED和self.profile.native_events_enabled)AttributeError:"FirefoxBinary"对象没有属性 'native_events_enabled'

Traceback (most recent call last): File "C:/Python34/torfirstscript.py", line 10, in browser=webdriver.Firefox( binary, profile) File "C:\Python34\lib\site-packages\selenium-2.43.0-py3.4.egg\selenium\webdriver\firefox\webdriver.py", line 46, in init self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled) AttributeError: 'FirefoxBinary' object has no attribute 'native_events_enabled'

通过申请

browser=webdriver.Firefox( firefox_binary = binary, firefox_profile = profile)

我收到此错误:

回溯(最近通话最近): 在第9行的文件"C:\ Python34 \ torfirstscript.py" browser = webdriver.Firefox(firefox_binary =二进制,firefox_profile => profile) init 中的文件"C:\ Python34 \ lib \ site-packages \ selenium-2.43.0-> py3.4.egg \ selenium \ webdriver \ firefox \ webdriver.py",第59行 self.binary,超时), > init 中的文件"C:\ Python34 \ lib \ site-packages \ selenium-2.43.0-> py3.4.egg \ selenium \ webdriver \ firefox \ extension_connection.py",第47行 self.binary.launch_browser(self.profile) 在launch_browser中的第64行,文件"C:\ Python34 \ lib \ site-packages \ selenium-2.43.0-> py3.4.egg \ selenium \ webdriver \ firefox \ firefox_binary.py" self._wait_until_connectable() 文件"C:\ Python34 \ lib \ site-packages \ selenium-2.43.0-py3.4.egg \ selenium \ webdriver \ firefox \ firefox_binary.py",行108,位于_wait_until_connectable中 self.profile.path,self._get_firefox_output())) selenium.common.exceptions.WebDriverException:消息:无法加载配置文件.配置文件目录:> C:\ Users \ HPPAV1〜1 \ AppData \ Local \ Temp \ tmpig7zvx_0 \ webdriver-py-profilecopy Firefox输出:无"

Traceback (most recent call last): File "C:\Python34\torfirstscript.py", line 9, in browser=webdriver.Firefox( firefox_binary = binary, firefox_profile = >profile) File "C:\Python34\lib\site-packages\selenium-2.43.0->py3.4.egg\selenium\webdriver\firefox\webdriver.py", line 59, in init self.binary, timeout), File "C:\Python34\lib\site-packages\selenium-2.43.0->py3.4.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in >init self.binary.launch_browser(self.profile) File "C:\Python34\lib\site-packages\selenium-2.43.0->py3.4.egg\selenium\webdriver\firefox\firefox_binary.py", line 64, in launch_browser self._wait_until_connectable() File "C:\Python34\lib\site-packages\selenium-2.43.0-py3.4.egg\selenium\webdriver\firefox\firefox_binary.py", line 108, in _wait_until_connectable self.profile.path, self._get_firefox_output())) selenium.common.exceptions.WebDriverException: Message: "Can't load the profile. Profile Dir: >C:\Users\HPPAV1~1\AppData\Local\Temp\tmpig7zvx_0\webdriver-py-profilecopy Firefox output: None"

以该图像作为输出.

推荐答案

在Windows上使用Selenium和Tor的有效示例:

A working example with Selenium and Tor on windows :

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")
driver.save_screenshot("screenshot.png")
driver.quit()

这篇关于带有TOR浏览器的Python Selenium绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆