selenium
macOS selenium
- 系列文章目录
- 前言
- 一、ChromeDriver下载
- 方法2 通过brew安装
- 二、安装selenium
- 1.pip
- 三、selenium基本使用
- 2.测试
- 3. 打开百度搜索内容
- 参考
前言
selenium:Web应用程序测试工具
一、ChromeDriver下载
ChromeDriver
chromedriver_mac64_m1.zip
- Latest stable release: ChromeDriver 102.0.5005.61
chromedriver
brew install --cask chromedriver
╰─➤ brew install --cask chromedriver 1 ↵ Running `brew update --preinstall`... ==> Auto-updated Homebrew! Updated 6 taps (homebrew/cask-versions, homebrew/command-not-found, homebrew/core, homebrew/cask, homebrew/cask-fonts and homebrew/cask-drivers). ==> New Formulae bore-cli dtrx flix hatch naml terramate xpipe cxgo erlang@24 gokart helmify opentelemetry-cpp tinysearch ==> Updated Formulae Updated 398 formulae. ==> New Casks bili-downloader cardpresso hdfview oso-cloud rustdesk xmind8 bilibili-official contour input-source-pro roam-research swiftcord ==> Updated Casks Updated 335 casks. ==> Deleted Casks coarchi font-gentium-plus-book race-into-space xmind-zen crystax-ndk plistedplus stubbymanager yammer ==> Downloading https://chromedriver.storage.googleapis.com/102.0.5005.61/chromedriver_mac64_m1.zip ######################################################################## 100.0% ==> Installing Cask chromedriver ==> Linking Binary 'chromedriver' to '/opt/homebrew/bin/chromedriver' chromedriver was successfully installed!
╰─➤ chromedriver --version
╰─➤ chromedriver --version
ChromeDriver 102.0.5005.61 (0e59bcc00cc4985ce39ad31c150065f159d95ad3-refs/branch-heads/5005@{#819})
二、安装selenium
1.pip
╰─➤ pip install selenium
- 验证
╰─➤ python Python 3.9.12 (main, May 8 2022, 17:57:49) [Clang 13.1.6 (clang-1316.0.21.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> import selenium >>>三、selenium基本使用 2.测试
test01.py
from selenium import webdriver driver = webdriver.Chrome() base_url = 'https://www.baidu.com' driver.get(base_url)3. 打开百度搜索内容
from selenium import webdriver
import time
# 创建浏览器对象
driver = webdriver.Chrome()
# 打开浏览器
url = 'https://www.baidu.com'
driver.get(url)
time.sleep(2)
# 获取输入框对象
input = driver.find_element_by_id("kw")
# 输入内容
input.send_keys("macos")
time.sleep(2)
# 获取点击按钮对象
button = driver.find_element_by_id("su")
# 点击按钮
button.click()
time.sleep(5)
# 退出浏览器
driver.quit()
参考
- ChromeDriver
- chromedriver_mac64_m1.zip
- 尚硅谷Python爬虫教程小白零基础速通(含python基础+爬虫案例)



