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()
相关推荐
巴里巴气12 小时前
对selenium进行浏览器和驱动进行配置Windows | Linux
selenium·测试工具
q567315231 天前
Java Selenium反爬虫技术方案
java·爬虫·selenium
有趣的我1 天前
wireshark介绍和使用
网络·测试工具·wireshark
草履虫建模1 天前
Postman - API 调试与开发工具 - 标准使用流程
java·测试工具·spring·json·测试用例·postman·集成学习
龙潜月七1 天前
Selenium 自动化测试中跳过机器人验证的完整指南:能用
python·selenium·机器人
AIZHINAN1 天前
如何评价 selenium 自动化测试框架搭建?
selenium·测试工具
WIN赢11 天前
PostMan使用
测试工具·lua·postman
百里图书12 天前
颠覆传统接口测试!用 Streamlit + SQLite + GPT 打造可视化自动化平台
自动化测试·测试开发·接口自动化测试·测试工具·接口测试·测试平台·python编程
笑口常开的小丸子12 天前
Selenium等待机制详解:从原理到实战应用
selenium
网络安全小吗喽12 天前
靶场(二十六)---小白心得&&靶场体会---Readys
服务器·网络·测试工具·网络安全·靶机