我想通过 Flask 应用程序上的 POST 请求运行 Selenium,并希望它能够自动化操作。它在本地完美运行,但是当我尝试将其部署在 Pythonanywhere 上时,我收到如下错误:
运行 WSGI 应用程序时出错 Selenium.common.exceptions.SessionNotCreatedException:消息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 90 当前浏览器版本为 115.0.5790.170,二进制路径为 /home/usmmsmsm/.cache/selenium/chrome/linux64/115.0.5790.170/chrome
我尝试通过 webdriver-manager 更新浏览器,使用以下代码:
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
# Initialize the WebDriver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
但是,我在错误日志中收到以下错误: 运行 WSGI 应用程序时出错 selenium.common.exceptions.SessionNotCreatedException:消息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 114 当前浏览器版本为 90.0.4430.212,二进制路径为 /usr/bin/chromium
这确实让我很困扰。另外,在 Flask 应用程序中通过 POST 请求请求 Selenium,并部署在 Web 上,真的也可能吗?如果能得到答复,我将不胜感激。非常感谢!
不要在 PythonAnywhere 上使用 chromedriver 管理器。只需使用已安装的默认 chromedriver 和 chrome 即可。