【问题标题】:Unable to use Selenium on PythonAnywhere无法在 PythonAnywhere 上使用 Selenium
【发布时间】:2021-01-18 12:12:12
【问题描述】:

我正在尝试在 PythonAnywhere 上设置一个使用 Selenium 和 Chrome 的 Python 应用程序。一切都在开发环境中运行,但是在尝试部署到 PythonAnywhere 时遇到了问题。尝试运行代码时,我得到以下回溯:

Traceback (most recent call last):
  File "/home/mattk/Door_Price/main.py", line 51, in <module>
    main()
  File "/home/mattk/Door_Price/main.py", line 13, in main
    catalog = Catalog(silent=True)
  File "./driver.py", line 29, in __init__
    self.driver = self._create_engine(path or config.PATH, silent)
  File "./driver.py", line 60, in _create_engine
    driver = Chrome(
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 65, in __init__
    RemoteWebDriver.__init__(
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}),platform=Linux 5.4.0-1020-aws x86_64)

不确定 PythonAnywhere 是否需要一些特殊配置? 对此问题的任何帮助将不胜感激。

导致错误的代码: @静态方法 def _create_engine(路径,静默): """生成 Selenium 引擎"""

    # TODO check if driver is present

    if silent:
        options = ChromeOptions()
        options.add_argument('--headless')
        driver = Chrome(
            executable_path=path,
            options=options
        )
    else:
        driver = Chrome(
            executable_path=path
        )

    return driver

【问题讨论】:

  • 请添加返回错误的代码部分。
  • @Jortega 我已经添加了代码
  • 错误说问题来自这里File "/home/mattk/Door_Price/main.py", line 13, in main catalog = Catalog(silent=True)你能添加这部分代码吗?
  • 写信给 support@pythonanywhere.com 为您的帐户启用所需的功能。

标签: python selenium selenium-webdriver selenium-chromedriver pythonanywhere


【解决方案1】:

您提交的内容有些混乱。我认为要在 pythonanywhere 上安装,您需要添加“用户”标志。你试过这个吗?:

pip3 install [package] --user

在你的情况下:

pip3 install selenium --user

但是从你的这部分追溯:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}),platform=Linux 5.4.0-1020-aws x86_64)

看起来 selenium 已经安装了。

【讨论】:

  • Selenium 已安装。 PythonAnywhere 是否需要任何特殊配置才能在 Chrome 中运行 Selinum?
  • 你最好在 pythonanywhere 论坛中问这个问题:pythonanywhere.com/forums
【解决方案2】:

解决了。 PythonAnyWhere 需要在帐户上启用一些测试版功能。

【讨论】:

    【解决方案3】:

    默认情况下,您不能在 Chrome 上使用 PythonAnywhere 和 Selenium,您需要 Firefox 17。 检查这个:https://help.pythonanywhere.com/pages/selenium/

    【讨论】:

    • 默认情况下您不能这样做,但您可以写信至 support@pythonanywhere.com 为您的帐户启用所需的功能。
    猜你喜欢
    • 2016-02-05
    • 2021-02-22
    • 2016-01-22
    • 2019-02-20
    • 2015-03-06
    • 2022-12-13
    • 2019-05-14
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多