我正在使用 Python 開發語音助手。我在運行我的代碼時不斷收到此錯誤...
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects\pythonProject\Python_Bot.py", line 40, in <module>
browser_driver.get('https://www.youtube.com/')
File "C:\Users\Admin\Python3.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\Admin\Python3.9\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\Python3.9\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: chrome=94.0.4606.71)
從Session info: chrome=94.0.4606.71訊息中,我發現當我的驅動程式版本是 94.0.4606.61 時,我使用的是 Chrome 版本 94.0.4606.71。(我使用 Selenium 的 Chrome 驅動程式管理器來找出我的 Chrome 驅動程式版本)順便說一句,我的 selenium 版本是最新的。所以我想知道將 Chrome 版本從我當前的版本降級到我的驅動程式版本是否會消除這個錯誤。如果這是解決方案,我如何安全地降級 Chrome 而不會遇到任何問題?如果降級 Chrome 不是解決方案,那么什么才是?順便說一句,我在這里問了一個類似的問題。
(如果需要,我的語音助手的代碼......)
import datetime
import webbrowser
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
import speech_recognition as sr
import pyttsx3
import pyaudio
import os
import random
import gtts
browser_driver = webdriver.Chrome(ChromeDriverManager().install())
r1 = sr.Recognizer()
r2 = sr.Recognizer()
r3 = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
with sr.Microphone() as source:
print('Listening...')
engine.say("Hey I'm your bot, Trevor! What can I do for you today?")
engine.runAndWait()
audio = r3.listen(source)
# From here
if 'YouTube' in r2.recognize_google(audio):
r2 = sr.Recognizer()
with sr.Microphone() as source:
print("What do you want to see?", end='')
audio = r2.listen(source)
keyword = audio
browser_driver.get('https://www.youtube.com/')
elem = browser_driver.find_element_by_id('search')
elem.send_keys(keyword , Keys.RETURN)
browser_driver.quit()
try:
get = r2.recognize_google(audio)
print(get)
except sr.UnknownValueError:
print('Error on your side')
except sr.RequestError:
print('Error on my side')
# Till here is the code to run a YouTube vid
PS:代碼和錯誤資訊都按照 Pycharm 的縮進進行了縮進
我已經面臨這個問題好幾天了,所以我真的很感激一些幫助......
uj5u.com熱心網友回復:
您似乎以錯誤的方式呼叫網路驅動程式。
嘗試:
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
service = Service('theWebDriverPATH\\chromedriver.exe')
chrome_options = Options()
chrome_options.add_argument \
(r"--user-data-dir=C:\\Users\\yourWindowsUser\\AppData\\Local\\Google\\Chrome\\User Data")
chrome_options.add_argument(r'--profile-directory=ThePofileYouWantToUse')
driver = webdriver.Chrome(service=service, options=chrome_options)
如果你有你提到的正確版本的網路驅動程式,它應該可以作業
請注意,WebDriverPATH 應該是以下形式的東西 C:\\Users\\nicoc\\PycharmProjects
編輯 我建議更新 Chrome 和驅動程式的最新可用版本(當前為 94.0.4606.71 和 95.0.4638.17)以避免出現問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/312661.html
