[Python] 执行selenium时,遇见selenium.common.exceptions.SessionNot

目前环境为:uat./chromeDriver/linux/chromedriverTraceback (most recent call last):  File "web_scraping_start.py", line 24, in <module>  File "main.py", line 124, in main  File "main.py", line 52, in scan_seeds  File "utils/fn_get_web_driver.py", line 37, in fn_get_web_driver  File "selenium/webdriver/chrome/webdriver.py", line 81, in __init__  File "selenium/webdriver/remote/webdriver.py", line 157, in __init__  File "selenium/webdriver/remote/webdriver.py", line 252, in start_session  File "selenium/webdriver/remote/webdriver.py", line 321, in execute  File "selenium/webdriver/remote/errorhandler.py", line 242, in check_responseselenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.  (session not created: DevToolsActivePort file doesn't exist)  (The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

解法:

加入
options = webdriver.ChromeOptions()options.add_argument("--headless")options.add_argument("--disable-gpu")options.add_argument("--no-sandbox")options.add_argument("--disable-dev-shm-usage")
更新或是安装chrome的时候,记得将chrome权限,全开
// shellsudo chmod 777 ./chrome// 用sudo执行sudo ./web_scraping_start uat 

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章