2015-05-13 24 views
2

我正在尋找一種方式來使用python和selenium驅動phantomjs回調,但我無法使它的工作,我想用一個簡單的例子,如更新標題stackoverflow.com網站一旦網站被加載,使用從phantomjs文檔使用phantomjs回調蟒蛇和硒驅動

http://phantomjs.org/api/webpage/handler/on-load-finished.html

onLoadFinished回調,但它可以是任何其它事件回調,並在這裏我使用

#!/usr/bin/env python 

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 

user_agent = (
    "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)) " + 
    "AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3" 
) 

dcap = dict(DesiredCapabilities.PHANTOMJS) 
dcap["phantomjs.page.settings.userAgent"] = user_agent 
dcap["phantomjs.page.onLoadStarted"] = "function() {document.title = 'test';};" 

driver = webdriver.PhantomJS(desired_capabilities=dcap) 

driver.get("http://stackoverflow.com/") 
url = driver.current_url 
print "title: " + driver.title 

任意代碼如果這是可能的想法或者如果我做錯了什麼? 謝謝你提前

回答

-1

PhantomJS最近完全放棄了Python的支持。不過,PhantomJS現在嵌入了Ghost Driver。

一個新項目已經加緊填補空白:Ghost.py(http://jeanphix.me/Ghost.py/)。