Selenium安装
-
Selenium的官网: https://www.selenium.dev
- 安装与查看
pip install selenium
pip show selenium
(mypy3) peter@~/workspace1/mypy3 $ pip show selenium Name: selenium Version: 4.27.1 Summary: Official Python bindings for Selenium WebDriver Home-page: https://www.selenium.dev Author: Author-email: License: Apache 2.0 Location: /home/peter/workspace1/mypy3/lib/python3.12/site-packages Requires: certifi, trio, trio-websocket, typing_extensions, urllib3, websocket-client
- 安装Chrome driver,它假定你本地已安装了Chrome或Chromium浏览器。本地已经安装了Chromium。
Chromium Version 131.0.6778.139 (Official Build) snap (64-bit)
sudo apt update
sudo apt install chromium-chromedriver
- 所以使用apt安装Chrome driver还是非常方便的,安装后可以检查是否安装成功
chromedriver --version
ChromeDriver 131.0.6778.139 (c35bbcbd7c2775a12a3f320e05ac0022939b1a8a-refs/branch-heads/6778@{#2771})
- 最后,使用脚本测试一下打开一个简单的网页
python webd/selemium_test.py
from selenium import webdriver import time browser = webdriver.Chrome() browser.get('https://www.sohu.com/') time.sleep(10) browser.quit()
- 总体上安装还是非常简单的,Windows系统需要手动安装driver并添加到PATH。