简体   繁体   English

Chromedriver 硒 python

[英]Chromedriver selenium python

i am working on a python project using selenium.我正在使用 selenium 开发一个 python 项目。

I get the following error and would like some help please我收到以下错误,需要一些帮助

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status from unknown error: unexpected command response (Session info: chrome=103.0.5060.114) selenium.common.exceptions.WebDriverException:消息:未知错误:无法从未知错误确定加载状态:意外命令响应(会话信息:chrome=103.0.5060.114)

My chrome is version 103, and so is my chrome driver.我的 chrome 是 103 版,我的 chrome 驱动程序也是如此。

Here is the code这是代码

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service

player = input("Which player: ").lower()
PATH = "/Users/makfadel/Desktop/Desktop-items/chromedriver 2"
#driver = webdriver.Chrome(PATH)

s = Service(PATH)
browser = webdriver.Chrome(service=s)
browser.get("https://www.basketball-reference.com/leagues/NBA_2022_per_game.html")
search = browser.find_element(By.XPATH, "//*[@id='header']/div[3]/form/div/div/input[2]")
search.send_keys(player)
search.send_keys(Keys.RETURN)

try:
    element = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='players']/div[1]/div[1]/strong/a")))
    element.click()
    name = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='meta']/div[2]/h1/span")))
    print()
    print(name.text)
    print()
    szn = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[1]/div/p[1]/strong"))
    )
    games = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[2]/div[1]/p[1]"))
    )
    ppgame = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[2]/div[2]/p[1]"))
    )
    rebounds = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[2]/div[3]/p[1]"))
    )
    assists = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[2]/div[4]/p[1]"))
    )
    fg = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[3]/div[1]/p[1]"))
    )
    fg3 = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[3]/div[2]/p[1]"))
    )
    ft = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.XPATH, "//*[@id='info']/div[4]/div[3]/div[3]/p[1]"))
    )
    print(f"Season: {szn}")
    print(f"Games played: {games.text}")
    print(f"Points per game: {ppgame.text}")
    print(f"Rebounds per game: {rebounds.text}")
    print(f"Assists per game: {assists.text}")
    print(f"Field goal percentage: {fg.text}%")
    print(f"Field goal from 3 percentage: {fg3.text}%")
    print(f"Free throw percentage: {ft.text}%")
except Exception:
    print(f"No player named {player}")
finally:
    browser.quit()

There has been an issue with chrome driver 103 version chrome driver 103 版本出现问题

Please find below the bug ids for the same,请在下面找到相同的错误 ID,

https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121&q=label%3AMerge-Request-103 https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121&q=label%3AMerge-Request-103

Check it on GitHub Selenium Issue - https://github.com/SeleniumHQ/selenium/issues/10799在 GitHub Selenium 问题上检查它 - https://github.com/SeleniumHQ/selenium/issues/10799

Solution解决方案

  1. For now, until this issue is fixed try to "Downgrade Chrome Browser To v102" and "Download Selenium Chrome Driver 102" and try to run your script, as this issue is happening in 103 version.目前,在解决此问题之前,请尝试“将 Chrome 浏览器降级至 v102”“下载 Selenium Chrome 驱动程序 102”并尝试运行您的脚本,因为此问题发生在103版本中。

  2. Upgrade the chromedriver to v104将chromedriver升级到v104

sample code snippet -示例代码片段 -

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


// 1
option = Options()
option.binary_location='/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta'

// 2
driver = webdriver.Chrome(service=Service(ChromeDriverManager(version='104.0.5112.20').install()), options=option)

code reference - https://www.globalnerdy.com/2022/06/30/fix-the-chromedriver-103-bug-with-chromedriver-104/代码参考 - https://www.globalnerdy.com/2022/06/30/fix-the-chromedriver-103-bug-with-chromedriver-104/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM