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

9w11ddsr  于 2024-01-06  发布在  Linux
关注(0)|答案(1)|浏览(143)

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

  1. Service /home/project/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver unexpectedly exited. Status code was: -5
  2. Traceback (most recent call last):
  3. File "/home/project/repositories/fam/fam.py", line 23, in init_browser
  4. browser = webdriver.Chrome(options)
  5. ^^^^^^^^^^^^^^^^^^^^^^^^^
  6. File "/home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
  7. super().__init__(
  8. File "/home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 53, in __init__
  9. self.service.start()
  10. File "/home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 102, in start
  11. self.assert_process_still_running()
  12. 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
  13. raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
  14. selenium.common.exceptions.WebDriverException: Message: Service /home/project/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver unexpectedly exited. Status code was: -5

字符串

Python代码:

  1. def init_browser():
  2. #Init browser
  3. logging.info("Initializing browser object")
  4. try:
  5. options = webdriver.ChromeOptions()
  6. options.add_argument('--headless=new')
  7. # block image loading
  8. options.experimental_options['prefs'] = {
  9. "profile.managed_default_content_settings.images": 2
  10. }
  11. browser = webdriver.Chrome(options=options)
  12. except Exception as ex:
  13. logging.exception(ex)
  14. sys.exit()
  15. else:
  16. return browser

相关日志输出

  1. shell
  2. Selenium Manager binary found at: /home/project/virtualenv/repositories/fam/3.11/lib/python3.11/site-packages/selenium/webdriver/common/linux/selenium-manager
  3. 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
  4. chromedriver not found in PATH
  5. chrome not found in PATH
  6. chrome not found in the system
  7. Discovering versions from https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json
  8. Required browser: chrome 119.0.6045.105
  9. chrome 119.0.6045.105 already exists
  10. chrome 119.0.6045.105 is available at /home/project/.cache/selenium/chrome/linux64/119.0.6045.105/chrome
  11. Discovering versions from https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
  12. Required driver: chromedriver 119.0.6045.105
  13. chromedriver 119.0.6045.105 already in the cache
  14. Driver path: /home/project/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver
  15. Browser path: /home/project/.cache/selenium/chrome/linux64/119.0.6045.105/chrome
  16. Using driver at: /home/qproject/.cache/selenium/chromedriver/linux64/119.0.6045.105/chromedriver
  17. 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,
  1. --remote-debugging-port=8080

新增参数:

  1. -disable-dev-shm-usage
  1. --no-sandbox

的字符串

及以上任何组合

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

  1. 2023-12-01 13:19:23 - INFO - root - Initializing browser object
  2. 2023-12-01 13:19:23 - INFO - root - Browser type is chrome
  3. 2023-12-01 13:19:23 - INFO - root - Local files are used
  4. 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
  5. 2023-12-01 13:19:24 - ERROR - root - Message: session not created: Chrome failed to start: exited normally.
  6. (session not created: DevToolsActivePort file doesn't exist)
  7. (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小时与我聊天,并尝试不同的解决方案后,他们转过身来说:

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

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

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

相关问题