我正在尝试将这个 google feed api 的示例翻译为与 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();
});
输出说:
ReferenceError: Can't find variable: google
我试过定义 var google;就在包含但没有运气之后。一般来说,我是 Phantomjs 和 js 的新手。任何指针都非常感谢。