Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Phantomjs使用Google提要API_Javascript_Rss_Phantomjs_Google Feed Api - Fatal编程技术网

Javascript 使用Phantomjs使用Google提要API

Javascript 使用Phantomjs使用Google提要API,javascript,rss,phantomjs,google-feed-api,Javascript,Rss,Phantomjs,Google Feed Api,我正在尝试翻译GoogleFeedsAPI以使用Phantomjs。根据Phantomjs的一篇文章,我有以下几点: var page = require('webpage').create(); page.onConsoleMessage = function(msg) { console.log(msg); }; // Our callback function, for when a feed is loaded. function feedLoaded(result) {

我正在尝试翻译GoogleFeedsAPI以使用Phantomjs。根据Phantomjs的一篇文章,我有以下几点:

var page = require('webpage').create();

page.onConsoleMessage = function(msg) {
    console.log(msg);
};

// Our callback function, for when a feed is loaded.
function feedLoaded(result) {
  if (!result.error) {
    // Loop through the feeds, putting the titles onto the page.
    // Check out the result object for a list of properties returned in each entry.
    // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON
    for (var i = 0; i < result.feed.entries.length; i++) {
      var entry = result.feed.entries[i];
      console.log(entry.title);
    }
  }
}


page.includeJs("http://www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0", function() {
    google.load("feeds", "1");
    var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
    feed.includeHistoricalEntries(); // tell the API we want to have old entries too
    feed.setNumEntries(250); // we want a maximum of 250 entries, if they exist

    // Calling load sends the request off.  It requires a callback function.
    feed.load(feedLoaded);

phantom.exit();
});

我曾经尝试过定义var-google;就在比赛结束后,但没有运气。我对Phantomjs和js都是新手。非常感谢任何指针。

因此,您使用includeJs回调的方式存在问题

您假设的函数是在页面上下文中执行的:它不是。它在主上下文中执行

您已经在页面中注入了一个库:很好。现在,我想,你想在那页里做些事情。 您必须使用以下功能:

page.evaluate(function, arg1, arg2, ...);
此外,我看到您希望收到以下结果:

feed.load()
在回拨中。这很好,但您需要弥合这一差距:页面上下文中的回调还不能在虚拟上下文中调用!。你需要读一点文档,看看你想如何提出你的解决方案

赤裸裸的头脑:打电话给

page.evaluate()

可以返回JSON和其他JS简单类型字符串、数字、布尔值:这应该是你的门

谢谢,我已经包含了evaluate调用并删除了回调,因此不需要桥接,但现在我没有从脚本中获得任何输出。。。你没有真正回答这个问题。如果你想争取选票,你必须做得更好。
page.evaluate()