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()
相关推荐
鱼鱼说测试1 小时前
postman测试文件上传教程
测试工具·postman
程序员的世界你不懂10 小时前
基于Java+Maven+Testng+Selenium+Log4j+Allure+Jenkins搭建一个WebUI自动化框架(2)对框架加入业务逻辑层
java·selenium·maven
程序员的世界你不懂13 小时前
基于Java+Maven+Testng+Selenium+Log4j+Allure+Jenkins搭建一个WebUI自动化框架(4)集成Allure报表
java·selenium·maven
MYians4 天前
[Windows]Postman-app官方历史版本下载方法
测试工具·postman
巴里巴气4 天前
selenium基础知识 和 模拟登录selenium版本
爬虫·python·selenium·爬虫模拟登录
2501_924064114 天前
2025年跨端云真机测试平台深度测评:XR与折叠屏时代的兼容性之战
测试工具·移动端自动化测试·自动化测试脚本
Small black human4 天前
HTTP-Postman的安装及其使用
测试工具·postman
AIZHINAN5 天前
Appium 简介
自动化测试·测试工具·appium
吴free5 天前
mac电脑wireshark快速实现http接口抓包
网络·测试工具·http·wireshark