我不断遇到Web驱动器异常错误,而有时也可以工作

发布于 2025-02-12 06:47:14 字数 1695 浏览 1 评论 0原文

我不断遇到各种WebDriver错误,然后随机运行。如何解决正在发生的错误,以便可以运行我要做的事情的完整版本?

最新的是:WebDriverexception:未知错误:意外命令响应 (会话信息:chrome = 103.0.5060.66)

from selenium import webdriver
import time
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup


PATH = "C:\Program Files (x86)\Chrome\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.maximize_window()

ytournaments = ['/dpworld-tour/abu-dhabi-hsbc-championship-2021/', '/dpworld-tour/omega-dubai-desert-classic-2021/']

roundids = [1, 2, 3, 4]

for tournamentid in ytournaments:
    
    for roundid in roundids:
        
        page = driver.get(f"https://www.europeantour.com{tournamentid}leaderboard?holebyhole=true&round={roundid}")
        time.sleep(10)
        html = driver.page_source
        soup = BeautifulSoup(html, 'lxml')
        
        Tour = 'European Tour'
        Year = '2021'
        
        tournamentm = soup.find('h1', class_='event-hero__title').text
        tournament = tournamentm.strip()
        
        coursem = soup.find('p', class_='event-hero__location').text
        course = coursem.strip()
        
        datem = soup.find('p', class_='event-hero__date').text
        date = datem.strip()
        
        dfs = pd.read_html(driver.page_source)
        df = dfs[0]
        ndf = np.squeeze(dfs)
        data = pd.DataFrame(ndf)
        
        data["tournament"] = tournament
        data["course"] = course
        data["date"] = date
        data["roundid"] = roundid
        data["Tour"] = Tour
        data["Year"] = Year
        
        filename = f'{tournament}_{roundid}_{Year}.csv'
        data.to_csv(filename)
    
driver.quit()

I keep getting a variety of WebDriver errors and then randomly it will run properly. How do i fix the error that is happening so that i can run the full version of what i am trying to do?

The latest one was : WebDriverException: unknown error: unexpected command response
(Session info: chrome=103.0.5060.66)

from selenium import webdriver
import time
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup


PATH = "C:\Program Files (x86)\Chrome\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.maximize_window()

ytournaments = ['/dpworld-tour/abu-dhabi-hsbc-championship-2021/', '/dpworld-tour/omega-dubai-desert-classic-2021/']

roundids = [1, 2, 3, 4]

for tournamentid in ytournaments:
    
    for roundid in roundids:
        
        page = driver.get(f"https://www.europeantour.com{tournamentid}leaderboard?holebyhole=true&round={roundid}")
        time.sleep(10)
        html = driver.page_source
        soup = BeautifulSoup(html, 'lxml')
        
        Tour = 'European Tour'
        Year = '2021'
        
        tournamentm = soup.find('h1', class_='event-hero__title').text
        tournament = tournamentm.strip()
        
        coursem = soup.find('p', class_='event-hero__location').text
        course = coursem.strip()
        
        datem = soup.find('p', class_='event-hero__date').text
        date = datem.strip()
        
        dfs = pd.read_html(driver.page_source)
        df = dfs[0]
        ndf = np.squeeze(dfs)
        data = pd.DataFrame(ndf)
        
        data["tournament"] = tournament
        data["course"] = course
        data["date"] = date
        data["roundid"] = roundid
        data["Tour"] = Tour
        data["Year"] = Year
        
        filename = f'{tournament}_{roundid}_{Year}.csv'
        data.to_csv(filename)
    
driver.quit()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千紇 2025-02-19 06:47:17

可能是您已更新了Google Chrome吗?在Google设置 /关于Chrome中检查Google Chrome版本。 eg: My Chrome version is 103.0.5060.66

Download and update Chromedriver to the version of your browser.希望这会有所帮助。

Could it be that you have updated Google Chrome? Check Google Chrome version in Google settings / About Chrome. e.g.: My Chrome version is 103.0.5060.66

Download and update Chromedriver to the version of your browser. Hope this helps.

太傻旳人生 2025-02-19 06:47:16

This is a known issue with 103.0.5060.66

https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121

From the link above here is a possible solution for now:

"Untill the issue is fixed "Downgrade Chrome Version到102“并安装” Selenium Chrome Driver v102“您的脚本将不用任何问题运行,就像我建议的“注释32”今天我尝试过的那样,它没有任何问题”

This is a known issue with 103.0.5060.66

https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121

From the link above here is a possible solution for now:

"Untill the issue is fixed "Downgrade Chrome Version to 102" and install "Selenium Chrome Driver v102" your script will run without any issue, As I had suggested "Comment 32" today I tried it and it worked without any issue"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文