selenium+ChromeDriver
所有chromedriver下載地址
http://chromedriver.storage.googleapis.com/index.html
selenium之 chromedriver與chrome版本映射表參考該博客
http://blog.csdn.net/huilan_same/article/details/51896672
配置
將chromedriver.exe直接放置在chrome.exe同目錄下

代碼
from selenium import webdriver
import time
#復制chromdriver路徑
driver_path = r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path)
driver.get("http://www.acfun.cn/")
#讓瀏覽器停留
time.sleep(1)
driver.close()
selenium+Geckodriver
Firefox的驅動器Geckodriver似乎無需像Chrome那樣,根據(jù)瀏覽器版本選擇匹配的驅動器版本。
geckodriver下載地址
https://github.com/mozilla/geckodriver/releases
配置

代碼
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
?
driver_path = r'C:\Program Files (x86)\Mozilla Firefox\geckodriver.exe'
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary,executable_path=driver_path)
driver.get("http://www.acfun.cn/")
#讓瀏覽器停留
time.sleep(5)
driver.close()
selenium+Phantomjs
phantomjs用于異步加載,也就是動態(tài)網(wǎng)頁的抓取。PhantomJS是一個基于webkit的JavaScript API。它使用QtWebKit作為它核心瀏覽器的功能,使用webkit來編譯解釋執(zhí)行JavaScript代碼。任何你可以在基于webkit瀏覽器 做的事情,它都能做到。它不僅是個隱形的瀏覽器,提供了諸如CSS選擇器、支持Web標準、DOM操作、JSON、HTML5、Canvas、SVG等, 同時也提供了處理文件I/O的操作,從而使你可以向操作系統(tǒng)讀寫文件等。PhantomJS的用處可謂非常廣泛,諸如前端無界面自動化測試(需要結合 Jasmin)、網(wǎng)絡監(jiān)測、網(wǎng)頁截屏等。
PhantomJS安裝
在下面的網(wǎng)站選擇合適的版本安裝
裝好解壓后,把文件夾bin中的phantomjs.exe移到python安裝文件夾中,至此,就已經(jīng)在Win的環(huán)境下配置好了環(huán)境。
配置

代碼
from selenium import webdriver
driver_path = r'C:\Users\lenovo\AppData\Local\Programs\Python\Python35\phantomjs.exe'
base_url = "http://hotel.qunar.com/"
driver = webdriver.PhantomJS(executable_path=driver_path)
driver.get(base_url)
?
html = driver.title
print(html)
driver.close()