Selenium配置與安裝以及相應瀏覽器的驅動配置
1. 通過pycharm添加selenium庫
2. 因爲selenium庫中的webdriver好像所有的都要用到,而且關聯的一般爲chrome,firefox和phantomjs所以需要另外下載這三個的驅動。下載地址:
http://npm.taobao.org/mirrors/chromedriver
http://phantomjs.org/download.html
https://github.com/mozilla/geckodriver/releases/ (firefox驅動)
3. win上解壓到文件夾,然後需要配置系統環境變量
a. 打開環境變量找到Path
b. 將驅動的地址複製粘貼到裏面,然後每個環境變量之間通過;隔開
c. 確定即可(可能需要重啓才生效)
4. Mac上則需要再finda中菜單的前往->前往文件夾,或者用command+shift+G然後進入/usr/local/bin,將安裝好的驅動粘貼在這裏
5. 即可使用from selenium import webdriver,driver=webdriver.FireFox()
3. 可以在代碼中設置Path=“驅動安裝的位置”
4.
from selenium import webdriver driver=webdriver.PhantomJS(executable_path=Path)