mac+python3+selenium 4

下载自己的版本

ChromeDriver - WebDriver for Chrome - Downloadshttps://chromedriver.chromium.org/downloads

https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.jsonhttps://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json

把下载好的程序 Google Chrome for Testing.app 解压到 /usr/local/bin/

双击打开试一下,如果打不开,
sudo xattr -d com.apple.quarantine /拖动APP

然后重命名为 chromedriver

.app扩展名也去掉

python 复制代码
from selenium import webdriver

from time import sleep
from selenium.webdriver.common.by import By

# 启动浏览器驱动
driver = webdriver.Chrome()

# 访问url
driver.get('https://www.baidu.com')

# 定位元素
el = driver.find_element(By.ID, 'kw')

# 执行自动化操作
el.send_keys('热搜')
driver.find_element(By.ID, 'su').click()
# 休眠5秒
sleep(5)

# 关闭浏览器并释放进程资源
# driver.quit()
相关推荐
love530love19 小时前
Windows 11 下 Z-Image-Turbo 完整部署与 Flash Attention 2.8.3 本地编译复盘
人工智能·windows·python·aigc·flash-attn·z-image·cuda加速
MediaTea20 小时前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
jarreyer20 小时前
python,numpy,pandas和matplotlib版本对应关系
python·numpy·pandas
代码or搬砖20 小时前
HashMap源码
开发语言·python·哈希算法
顽强卖力1 天前
第二章:什么是数据分析师?
笔记·python·职场和发展·学习方法
站大爷IP1 天前
Python实现Excel数据自动化处理:从繁琐操作到智能流程的蜕变
python
BBB努力学习程序设计1 天前
Python 进阶知识点精讲:上下文管理器(Context Manager)的原理与实战
python·pycharm
清水白石0081 天前
《深入 super() 的世界:MRO 与 C3 线性化算法的全景解析与实战指南》
python
大厂技术总监下海1 天前
Python 开发者的“新引擎”:Rust 编写的解释器,性能与安全兼得
python·开源
Swizard1 天前
别再硬编码配置了!5分钟带你用 PyYAML 让 Python 项目“活”起来
python