WebDriverException:消息:未知错误:Chrome 无法启动:异常退出。 (未知错误:DevToolsActivePort 文件不存在)

问题描述 投票:0回答:0

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.)

Windows 11 64 位 Chrome 驱动程序执行错误。 Chrome 版本是 111.0.5563.147 但为什么没有那个版本的驱动程序? 我如何在下面的代码中进行故障排除

!pip install beautifulsoup4 selenium Pillow
!pip install webdriver-manager
!apt-get update
!apt install -y chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin

import os
import sys
from bs4 import BeautifulSoup
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PIL import Image


chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-infobars')
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--start-maximized')
sys.path.insert(0, '/usr/lib/chromium-browser/chromedriver')
webdriver_path = r"C:\Program Files\Google\Chrome\Application\chrome.exe"


url = "https://ddolcat.tistory.com/674"


response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')


for tag in soup(['header', 'nav', 'footer']):
    tag.decompose()


driver = webdriver.Chrome(executable_path=webdriver_path, options=chrome_options)
driver.get(url)


driver.execute_script("document.documentElement.innerHTML = `{}`".format(soup.prettify()))


element = driver.find_element_by_tag_name('body')
element.screenshot('content_screenshot.png')


driver.quit()


from IPython.display import Image as DisplayImage
DisplayImage(filename='content_screenshot.png')

driver = webdriver.Chrome(executable_path=webdriver_path, options=chrome_options)

google-chrome google-colaboratory
© www.soinside.com 2019 - 2024. All rights reserved.