【问题标题】:Use phantomjs callbacks with python and selenium driver将 phantomjs 回调与 python 和 selenium 驱动程序一起使用
【发布时间】:2015-07-24 13:38:23
【问题描述】:

我正在寻找一种将 phantomjs 回调与 python 和 selenium 驱动程序一起使用的方法,但我无法使其正常工作,我正在尝试一个简单的示例,例如在站点更新后更新 stackoverflow.com 站点的标题加载,使用 phantomjs 文档中的 onLoadFinished 回调

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

但它可能是任何其他事件回调,这里是我正在使用的代码

#!/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

如果这是可能的或者我做错了什么,有什么想法吗? 提前谢谢你

【问题讨论】:

    标签: python-2.7 selenium phantomjs


    【解决方案1】:

    PhantomJS 最近完全放弃了对 Python 的支持。不过,PhantomJS 现在嵌入了 Ghost 驱动程序。

    此后,一个新项目填补了这一空白:Ghost.py (http://jeanphix.me/Ghost.py/)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多