我有一個RSS提要,並且需要從中爲我的測試提取最新的pubDate元素。做同樣的事情最好的方法是什麼?從RSS提要中提取XML元素值
RSS訂閱鏈接:https://secure.hyper-reach.com/rss/310085
示例XML:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="https://secure.hyper-reach.com/rss/310085" rel="self" type="application/rss+xml" />
<link>https://secure.hyper-reach.com/rss/310085</link>
<title>Hyper-Reach Automated Test Account alerts feed "Automated RSS Test"</title>
<description>Constant feed of alerts from Automated Test Account via hyper-reach.com</description>
<lastBuildDate>Fri, 21 Nov 2014 00:56:15 -0500</lastBuildDate>
<language>null</language>
<ttl>5</ttl>
<item>
<title>Alert (2014-11-21)</title>
<pubDate>Fri, 21 Nov 2014 00:56:15 -0500</pubDate>
<description>This is a test message.</description>
<link>https://secure.hyper-reach.com/servlet/getprompt?prompt_id=122967&ver=0&format=34&nologin=1</link>
<guid isPermaLink="false">https://secure.hyper-reach.com/rss/item/257029</guid>
</item>
<item>...</item>
<item>...</item>
</channel>
</rss>
我在做什麼:
checkRSSFeed = function() {
//first I navigate to a certain page in my website
var href = '';
casper.then(function() {
this.test.assertExists(x('//a[contains(@href, "SUBSTRING OF URL")]'), 'the element exists');
href = casper.getElementAttribute(x('//a[contains(@href, "SUBSTRING OF URL")]'), 'href');
}).then(function() {
this.open(href);
}).then(function() {
this.echo(this.getCurrentUrl());
var pubDate = '';
this.getPageContent();
pubDate = this._utils_.getElementByXPath('.//pubDate');
});
};
我得到的錯誤是
uncaughtError: TypeError: 'undefined' is not an object (evaluating 'this._utils_.getElementByXPath')