1.安裝
下載網址:http://phantomjs.org/download.html

選擇合適的版本。然后解壓即可。
環境變量的配置:

進入解壓的路徑:
例如我是解壓在D:/Python/phantomjs-2.1.1-windows/bin,將這個路徑編輯在上圖的末尾。就可以使用了。
如果剛配置好,在使用的時候,提示環境變量沒有配置好的話,不妨重啟一下電腦試試。
2 基本用法
引入:
from selenium import webdriver# 使用webkit無界面瀏覽器driver = webdriver.PhantomJS(executable_path=r'D:/Python/phantomjs-2.1.1-windows/bin/phantomjs.exe')
‘driver'的作用,去除里面的特殊字符的影響。
# 獲取指定網頁的數據driver.get('http://news.sohu.com/scroll/')print(driver.find_element_by_class_name('title').text)總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對VEVB武林網的支持。
新聞熱點
疑難解答