selenium 解决__init__() got an unexpected keyword argument ‘executable_path‘及初次使用

下载驱动chromedriver.exe到指定文件夹(例如:C:\\ProgramData\\Anaconda3\\Scripts\\chromedriver.exe)

python 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='C:\\ProgramData\\Anaconda3\\Scripts\\chromedriver.exe')
options = webdriver.ChromeOptions()
# 创建一个新的Chrome浏览器实例  
browser = webdriver.Chrome(service=service, options=options)  
  
# 导航到目标URL  
url = 'http://www.baidu.com/link?url=-N1zq8vCc8cCRK-Al85P7TUAcC0LbnRTcmhgb57Ij-RqoT5EkJ8yTh8f6LmsyXOFxUkqBvAhzMUQaZq4m-0r4kKFN7yV9drULA8lEzi1n4W'  
browser.get(url)  
  
# 等待页面加载完成(可选,但推荐,以确保获取完整的HTML)  
# 这里只是示例,你可能需要根据实际页面情况使用更具体的等待条件  
from selenium.webdriver.common.by import By  
from selenium.webdriver.support.ui import WebDriverWait  
from selenium.webdriver.support import expected_conditions as EC  
  
  
# 获取页面的HTML内容  
html_content = browser.page_source  
  
# 打印HTML内容(或者将其保存到文件、处理等)  
print(html_content)  
  
# 关闭浏览器  
browser.quit()
相关推荐
观音山保我别报错16 小时前
抽奖项目-接口自动化测试
功能测试·测试工具·单元测试
我的xiaodoujiao18 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 48--本地环境部署Jenkins服务
python·学习·测试工具·pytest
我的xiaodoujiao18 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 49--CI/CD-开始探索使用Jenkins
python·学习·测试工具·ci/cd·jenkins·pytest
学习3人组1 天前
Win11 使用 Proxifier 强制本地流量通过 Fiddler Classic 代理指南
前端·测试工具·fiddler
少云清1 天前
【UI自动化测试】2_web自动化测试 _Selenium环境搭建(重点)
前端·selenium·测试工具·web自动化测试
少云清2 天前
【UI自动化测试】1_web自动化测试 _测试工具选择
测试工具·web自动化测试
小妖6662 天前
有替代postman的软件吗
测试工具·postman
御坂10101号2 天前
Google Ads 转化凭空消失?问题藏在同意横幅的「时机」
前端·javascript·测试工具·网络安全·chrome devtools
德思特2 天前
德思特方案 | 突破户外测试局限:德思特GNSS仿真方案赋能机器人高精定位
经验分享·测试工具·信息与通信·电子测量仪器
0思必得02 天前
[Web自动化] Selenium获取网页元素在桌面上的位置
前端·python·selenium·自动化