mac本身自带Python2.7,但因Python2 版 20年以后不再维护,所以学习Python3 。
Python3下载地址:https://www.python.org/downloads/
Mac版下载安装后,就可以使用,不需像window去设置环境变量。验证是否安装成功,在终端输入:Python3 回车。出现Python3版本等信息就说明成功了。
使用Python集成pip工具安装;
pip install selenium # 默认调用Python2安装包,安装最新版
pip3 install selenium # pip3 才会调用python3的安装包,安装最新版
pip3 install selenium==3.11.0 # "==3.11.0"指定安装的版本
pip3 show selenium #查看当前包的版本信息
pip3 uninstall selenium #指定版本号安装
Chrome驱动下载地址
http://chromedriver.storage.googleapis.com/index.html
火狐驱动下载地址
https://github.com/mozilla/geckodriver/releases/
下载完成后,将驱动解压,拷贝到:usr/local/bin ;(可直接打开访达 command+shift+G ,输入路径即可)
安装后,
- 设置Sublime Text的语法为python
View -> syntax ->python
- 添加编译环境python3.6.5
Tools -> Build System -> New Build System
贴上一下代码
{
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.6/bin/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"env": {"PYTHONIOENCODING": "utf8"},
"selector": "source.python"
}
# 第一行是安装的Python的路径,查看Python路径,终端:which Python3
# 第三行是因为中文会报错
- 设置编译环境(即上一步保存的文件)
Tools -> Build System->选择文件
- 测试环境是否正确
打开sublime,输入Python代码,保存!后,command + B
编写如下脚本
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Selenium")
driver.find_element_by_id("su").click()
driver.quit()
Python3+selenium参考1,点击这里即可到达
Python3+selenium参考2,点击这里即可到达
sublime 参考3,点击这里即可到达
参考4,