Python / Selenium-webdrivers在cloudlinux x86 64位/ cpanel上不工作

9w11ddsr  于 5个月前  发布在  Linux
关注(0)|答案(1)|浏览(63)

我的解决方案可以在windows10上本地运行。使用python3.12
使用Python 3.11.5部署到Linux服务器,我得到了一个异常:

Service /home/project/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver unexpectedly exited. Status code was: -5
Traceback (most recent call last):
  File "/home/project/repositories/fam/fam.py", line 23, in init_browser
    browser = webdriver.Chrome(options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 53, in __init__
    self.service.start()
  File "/home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 102, in start
    self.assert_process_still_running()
  File "/home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 115, in assert_process_still_running
    raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
selenium.common.exceptions.WebDriverException: Message: Service /home/project/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver unexpectedly exited. Status code was: -5

字符串

Python代码:

def init_browser():
    #Init browser
    logging.info("Initializing browser object")
    try:
        options = webdriver.ChromeOptions()
        options.add_argument('--headless=new') 
        # block image loading
        options.experimental_options['prefs'] = {
        "profile.managed_default_content_settings.images": 2
        }
        browser = webdriver.Chrome(options=options)
    except Exception as ex:
        logging.exception(ex)
        sys.exit()
    else:
        return browser

相关日志输出

shell
Selenium Manager binary found at: /home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/common/linux/selenium-manager
Executing process: /home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/common/linux/selenium-manager --browser chrome --debug --output json
chromedriver not found in PATH
chrome not found in PATH
chrome not found in the system
Discovering versions from https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json
Required browser: chrome 119.0.6045.105
chrome 119.0.6045.105 already exists
chrome 119.0.6045.105 is available at /home/project/.cache/selenium/chrome/linux64/119.0.6045.105/chrome
Discovering versions from https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
Required driver: chromedriver 119.0.6045.105
chromedriver 119.0.6045.105 already in the cache
Driver path: /home/project/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver
Browser path: /home/project/.cache/selenium/chrome/linux64/119.0.6045.105/chrome
Using driver at: /home/qproject/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver
Started executable: `/home/project/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver` in a child process with pid: 365909


我在github SeleniumHQ上提交了一个bug。他们放弃了。希望你们能帮忙!https://github.com/SeleniumHQ/selenium/issues/13223
我试过什么?
我试着修改代码:

  • 为webdriver和浏览器可执行文件使用本地二进制文件
  • Chrome和Firefox
  • 使用自定义端口号,如8080和80,
--remote-debugging-port=8080

新增参数:

-disable-dev-shm-usage
--no-sandbox

的字符串

及以上任何组合

检查了Linux文件权限。你可以在github链接中看到它们。
我唯一的新错误是当我使用Chrome和我自己下载的二进制文件时:

2023-12-01 13:19:23 - INFO - root - Initializing browser object
2023-12-01 13:19:23 - INFO - root - Browser type is chrome
2023-12-01 13:19:23 - INFO - root - Local files are used
2023-12-01 13:19:23 - DEBUG - selenium.webdriver.common.service - Started executable: `/home/project/home/selenium_drivers/chromedriver-linux64/chromedriver` in a child process with pid: 1431566
2023-12-01 13:19:24 - ERROR - root - Message: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /home/project/home/selenium_bin/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

hrirmatl

hrirmatl1#

A2共享主机不支持“运行Chrome或Firefox的任何东西”

所以,经过几个小时的悲伤.我决定联系我的托管支持.他们花了1小时与我聊天,并尝试不同的解决方案后,他们转过身来说:

[16:35:21]  [name]: Unfortunately, we don't support puppet on shared hosting.
[16:35:35]  [name]: puppet/selenium/anything that runs chrome or firefox is not supported in shared hosting.

字符串
这不是他们的术语或知识库。你首先听到的是这里。

A2共享主机不支持“运行Chrome或Firefox的任何东西”

相关问题