【问题标题】:error while opening tor browser using Python selenium firefoxdriver使用 Python selenium firefoxdriver 打开 Tor 浏览器时出错
【发布时间】:2020-08-02 16:21:15
【问题描述】:

我正在尝试使用 selenium python 打开 Tor 浏览器

这是代码

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

#path to TOR binary
binary = FirefoxBinary(r'C:\Users\OKILAN\Desktop\Tor 
Browser\Browser\firefox.exe')
#path to TOR profile
profile = FirefoxProfile(r'C:\Users\OKILAN\Desktop\Tor 
Browser\Browser\TorBrowser\Data\Browser\profile.default')
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
driver =webdriver.Firefox(capabilities=cap,firefox_binary=binary,executable_path=r'C:\Users\OKILAN\Desktop\geckodriver.exe')
driver.get("http://stackoverflow.com")
time.sleep(5)

driver.quit()

当我运行代码时,它显示 tor 无法启动 我得到了以下错误

Traceback (most recent call last):
File "C:\Users\OKILAN\Desktop\test1.py", line 13, in <module>
driver = webdriver.Firefox(capabilities=cap,firefox_binary=binary,executable_path=r'C:\Users\OKILAN\Desktop\geckodriver.exe')
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 191, in __init__
self.binary, timeout)
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 73, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Users\OKILAN\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 104, in _wait_until_connectable
"The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

帮我解决这个错误:-(

【问题讨论】:

    标签: selenium-webdriver web-scraping python-3.7 tor tor-browser-bundle


    【解决方案1】:

    你不需要所有的二进制文件和配置文件,创建驱动程序只需要使用这一行

    driver = webdriver.Firefox(executable_path="C:\\geckodriver.exe")
    driver.get("http://stackoverflow.com")
    

    确保您已下载 geckodriver 并将其设置为环境 1

    1. 首先下载 GeckoDriver for Windows,解压并复制路径 到文件夹。

    2. 右键单击我的电脑或这台电脑。选择属性。

    3. 选择 高级系统设置。点击环境变量按钮。
    4. 从系统变量中选择 PATH。点击编辑按钮。点击新建 按钮。粘贴 GeckoDriver 文件的路径。

    【讨论】:

    • 嗨,阿德里安,我已经尝试过你的答案,我得到了“selenium.common.exceptions.SessionNotCreatedException:消息:无法找到一组匹配的功能”错误,我通过这个讨论解决了它link然后我收到一个新错误,如下所示“无法找到 firefox 二进制文件。您可以通过指定” selenium.common.exceptions.WebDriverException 进行设置:消息:无法找到 firefox 二进制文件。您可以通过指定 'firefox_binary' 的路径来设置它:
    • 你没有应用我的建议,我看到你还在使用二进制的东西确保你有 geckodriver 就是这样,你只需要调用我上面提到的那一行
    • 我已经按照你所说的更新了代码,但是我遇到了一个异常,如我在第一条评论中所说的无法找到一组匹配的功能,之后只有我使用一些堆栈更新了这样的代码溢出讨论和建议
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2016-03-22
    • 1970-01-01
    相关资源
    最近更新 更多