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

使用Selenium Chromedriver的.get方法时网页无法加载的问题

问题分析与解决方案

你的代码核心问题是Service对象传入的路径错误:你把Chrome浏览器程序(chrome.exe)的路径传给了Service,但Service需要的是**ChromeDriver驱动程序(chromedriver.exe)**的路径,这直接导致浏览器无法正常加载页面。另外原代码存在缩进语法错误,也需要修正。

修正步骤

  1. 匹配ChromeDriver与Chrome版本:确保ChromeDriver的版本和你本地安装的Chrome浏览器版本完全一致(可在Chrome「设置-关于Chrome」中查看版本号),版本不兼容是这类问题的常见诱因。
  2. 修正路径指向:将path变量改为ChromeDriver可执行文件的存放路径。
  3. 修复代码缩进:原代码中配置驱动的代码块存在多余缩进,会触发语法错误。

修正后的代码

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait

# 驱动参数配置
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
# 注意:这里是chromedriver.exe的路径,而非chrome.exe
path = "C:/Users/10200385/Downloads/chromedriver-win64/chromedriver.exe"
service = Service(path)
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://techwithtim.net")
print(driver.title)
driver.quit()

额外排查点

  • 确保路径中没有中文、空格或特殊字符,避免路径解析失败。
  • 若Chrome自动更新过,需同步更新ChromeDriver版本,保持二者版本匹配。

内容的提问来源于stack exchange,提问作者Adii

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 13:04:52