簡體   English   中英

selenium.common.exceptions.WebDriverException:消息:未知錯誤:無法使用帶有Selenium Python的ChromeDriver Chrome創建Chrome進程

[英]selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python

我正在嘗試使用 selenium 單擊一個按鈕,因此我使用 xpath 找到了該元素,因為我找不到 id 。 編輯:我認為其余的代碼與它沒有任何關系,但我添加了它以防萬一

這是代碼

import requests
import os
import selenium
from selenium import webdriver
os.system("cls")
print("                                         ")
print("______________     _____________         ________________")
print("| |         | |    |  |       | |        |______________|")
print("| |________ //     |  |  __   | |               | |")
print("| |________ \\\\     |  | |__|  | |               | |")
print("| |          | |   |  |       | |               | |")
print("| |__________| |   |__|_______|_|               |_|")

print("\u001b[34m Welcome To Movie Downloader")
print("\u001b[31m Please Make Sure To Not Put Every First Letter In Every Word Capital And Also Make Sure To Put Hyphens Instead Of Spaces Between Words, Also Put The Date The Movie Was Made")
print("\u001b[32m For Example: spider-man-homecoming-2017")


def Bot():
    URL = input("\u001b[34m What Movie Do You Want To Download:\n")
    r = requests.get("https://bila.egy.best/movie/" + URL + "/?ref=search-p1")
    if r.status_code == 200:
        print("\u001b[32m The Url Is Valid | Movie Has Been Found")
    else:
        print("\u001b[31m The Url Is Invalid")
    print("\u001b[0m")
    driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
    driver.get("https://bila.egy.best/movie/" + URL + "/?ref=search-p1")
    driver.find_element_by_xpath("//*[@id=watch_dl]/table/tbody/tr[2]/td[4]/a[1]").click()
Answer = input("Would You Like To Bot?")
if Answer == "Yes" or "yes" or "sure" or "Sure":
    Bot()

這是錯誤

Traceback (most recent call last):
  File "Movie_Download.py", line 32, in <module>
    Bot()
  File "Movie_Download.py", line 27, in Bot
    driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.

您需要注意以下幾點:

  • 在傳遞chromedriver二進制文件的絕對位置時,使用單個正斜杠和原始 ie r開關。 所以有效的代碼行將是:

     driver = webdriver.Chrome(executable_path=r'C:\\chromedriver.exe')
  • 非管理員/非 root用戶身份執行您的@Test


更新

另一個可能的原因是Chrome未按照規范安裝在默認位置:

Chrome_default_location

解決方案

可以有兩種方法來解決這種情況:

  • 卸載Chrome並在默認位置重新安裝Chrome
  • 使用binary_location屬性指向chrome二進制位置。

     from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" driver = webdriver.Chrome(chrome_options=options, executable_path="C:/Utility/BrowserDrivers/chromedriver.exe", ) driver.get('http://google.com/')

如果您仍然收到此錯誤,請嘗試重新安裝 chrome

它對我有用,我遇到了同樣的問題,我嘗試了所有方法,但仍然無法修復它,但是在我重新安裝 Chrome 瀏覽器后,它起作用了!

你必須編輯

driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")

driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")

你想念\\

如果出現同樣的錯誤,請嘗試以管理員身份運行

或者

chromedriver.exe移動到其他路徑,如c:/seleniumdriver/chromedriver.exe"並編輯executable_path

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM