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()
相关推荐
阿轲Jackson1 小时前
AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_id‘
python·selenium
Saniffer_SH3 小时前
【每日一题】PCIe链路协商的时候进入Polling compliance如何排错?
服务器·人工智能·驱动开发·嵌入式硬件·测试工具·fpga开发·自动化
张永清-老清4 小时前
每周读书与学习->Jmeter中如何使用Bean Shell脚本(二)Bean Shell的基础语法之变量与数据类型
学习·测试工具·jmeter·压力测试·性能调优·jmeter性能测试·性能分析
0和1的舞者16 小时前
高并发论坛系统:单元测试 + 接口自动化 + 性能测试 + CI/CD 全链路测试报告
java·测试开发·测试工具·jmeter·pytest·测试·测试报告
小杨的博客19 小时前
Java + Selenium实现浏览器打印功能
java·selenium
敷衍一下X19 小时前
Selenium元素定位
python·selenium·测试工具
汽车仪器仪表相关领域21 小时前
SSI-4 PLUS 简易传感器接口:多场景采集 “即插即用” 的终极解决方案
功能测试·测试工具·单元测试·压力测试·可用性测试·模块测试·安全性测试
Saniffer_SH1 天前
【高清视频】4小时带你了解Saniffer公司针对PCIe Gen6测试的最新白皮书15.X
网络·人工智能·驱动开发·嵌入式硬件·测试工具·计算机外设·压力测试
怪侠_岭南一只猿1 天前
爬虫阶段三实战练习题二:使用 Selenium 模拟爬取拉勾网职位表
css·爬虫·python·selenium·html