You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

网页爬取触发WebDriverException异常,请求排查(附相关代码)

WebDriverException 异常排查与解决方案

常见触发原因及对应解决办法

1. ChromeDriver与Chrome浏览器版本不匹配

这是触发该异常最普遍的原因,ChromeDriver版本必须和本地安装的Chrome浏览器版本严格对应。

  • 解决方式:
    • 打开Chrome,通过设置 -> 关于Chrome查看当前浏览器版本
    • 下载对应版本的ChromeDriver,或直接用webdriver-manager自动匹配版本(推荐,代码已导入该库但未使用)

2. 旧版Selenium语法兼容问题

代码中使用了已弃用的chrome_options参数,新版本Selenium(v4+)要求改用options参数。

3. 代码冗余与语法错误

  • 重复导入from selenium import webdriver,可删除其中一行
  • from bs4 import BeautifulSoupgives存在拼写错误,应改为from bs4 import BeautifulSoup

修正后的完整代码

from bs4 import BeautifulSoup
from selenium import webdriver
import requests
import statistics
from webdriver_manager.chrome import ChromeDriverManager

options = webdriver.ChromeOptions()
options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
# 自动获取匹配版本的ChromeDriver,无需手动指定路径
driver = webdriver.Chrome(options=options)
driver.get('https://russiabasket.ru/teams/718?apiUrl=https://asb.infobasket.su&compId=45595&lang=ru')

额外稳定性优化建议

  • 添加无头模式,避免弹出浏览器窗口:
    options.add_argument('--headless=new')
    
  • 添加禁用GPU、沙箱参数,提升运行稳定性:
    options.add_argument('--disable-gpu')
    options.add_argument('--no-sandbox')
    

内容的提问来源于stack exchange,提问作者Константин Озаржицкий

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 15:03:24