mac最新系統:OS X EI Captian
python: 本機自帶的python2.7。 (本來想升級3.5,覺得太復雜,放棄了)
pip: https://pypi.python.org/pypi/pip 下載版本pip 8.1.2.tar.gz (下載,解壓,cd到目錄,執行命令:sudo python setup.py install)
selenium :sudo easy_install selenium (聯網安裝,默認最新版,所以不用擔心沒有輸入版本號)
pycharm:版本2016.1 注冊碼如下
http://idea.lanyus.com/ 獲取最新注冊碼
注意事項:
1、使用python 的pip安裝selenium報錯
chenchengdeMacBook-Pro:~ NichoC$ sudo pip install -U selenium
Password:
The directory '/Users/NichoC/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/NichoC/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: selenium in /Library/Python/2.7/site-packages
chenchengdeMacBook-Pro:~ NichoC$
好像是權限不足,找了好多帖子沒解決,放棄,后來換了命令sudo easy_install selenium 安裝成功。
2、本機沒有安裝firefox ,嘗試其他瀏覽器的webdriver,都失敗,最后下載安裝firefox,不用配置path和路徑直接完成
推薦一個firefox 歷史版本下載地址,selenium對最新版本的firefox 支持不好,建議下載歷史版本:
http://ftp.mozilla.org/pub/firefox/releases/ (選擇版本號,選擇平台MAC,選擇語言zc-CN)
3、測試selenium安裝是否成功的用例(firefox彈出打開百度首頁然后關閉)
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.baidu.com")
browser.quit()