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()
相关推荐
小白学大数据6 小时前
爬虫进阶:Selenium与Ajax的无缝集成
大数据·开发语言·爬虫·selenium·ajax
小锋学长生活大爆炸11 小时前
【教程】新的Selenium!整合了隐藏浏览器指纹等功能
selenium·测试工具
PyAIGCMaster1 天前
selenium定位class中含有某段文字的方法
selenium·测试工具
xiaomu_3471 天前
基于selenium+python实现自动化测试
python·selenium·自动化
kingapex11 天前
自动化测试用例设计-软件测试在软件开发周期中的角色
测试工具·自动化·测试用例
FantanLee2 天前
Postman编写测试脚本
测试工具·postman
安得权2 天前
做测试/爬虫 selenium 元素定位 谷歌浏览器 插件推荐,提高元素定位效率
爬虫·selenium·测试工具
林渊羡鱼2 天前
Mac安装AndroidStudio&连接手机 客户端测试
测试工具·macos·android studio
kingapex12 天前
测试类型介绍-功能测试入门指南
自动化测试·功能测试·测试工具·ai
2402_857583492 天前
一文解决Postman请求发送难题
测试工具·lua·postman