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()
相关推荐
quantdash_cc6 分钟前
历史数据断层与REST请求慢到崩溃?QuantDash高性能量化数据API终极解决方案
开发语言·python·缓存·php·量化·quantdash
熊野君9 分钟前
Prompt / RAG / 规则 / Skills —— 定位、协作与实现路线
开发语言·python
aspirant-complete25 分钟前
MAC(Apple Silicon)嵌入式基于Clion(stm32CubeMX)环境搭建
stm32·macos
zhangphil35 分钟前
Python Web后端框架FastAPI vs Flask
python·ai·llm
ly76891 小时前
XML 从入门到实践:语法、命名空间、XPath、XSD 与 Java 安全解析
xml·java·python
winfredzhang1 小时前
用 Python + wxPython 造一个照片工具箱:PDF / 加密ZIP / MP4 / 归档,以及我在这过程中踩到的 4 个坑
python·pdf·zip·mp4·移动
卷无止境1 小时前
FastAPI 后台任务的边界,以及 Celery、Redis 与自建调度系统的选择
后端·python
卷无止境1 小时前
Linux + Docker + FastAPI 工程化实践指南
后端·python·fastapi
聪明蛋子哟11 小时前
Stagehand v3多语言SDK:Python/Go/Rust/Java下的浏览器自动化统一方案
python·golang·rust