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()
相关推荐
cup111 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi003 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵5 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf6 小时前
Agent 流程编排
后端·python·agent
copyer_xyf6 小时前
Agent RAG
后端·python·agent
copyer_xyf6 小时前
【RAG】向量数据库:milvus
后端·python·agent
元Y亨H6 小时前
MacBook Air 开发神器:IDEA 与 PyCharm 极简安装及环境配置
macos
copyer_xyf6 小时前
Agent 记忆管理
后端·python·agent
星云穿梭21 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python