0
我嘗試使用下面的代碼閱讀Slashdot的RSS訂閱閱讀RSS提要:無法使用節點的HTMLParser
var htmlparser = require("htmlparser");
var sys = require("sys");
var handler = new htmlparser.RssHandler(function (error, dom) {
if(error) throw error;
console.log(dom);
});
var parser = new htmlparser.Parser(handler);
parser.parseComplete("http://rss.slashdot.org/Slashdot/slashdotMain");
console.log(handler.dom);
sys.puts(sys.inspect(handler.dom, false, null));
而不是返回數組中總是送入它返回下列信息:
[ { data: 'http://rss.slashdot.org/Slashdot/slashdotMain',
type: 'text' } ]
問題是什麼 ?我的代碼有問題嗎?謝謝
文檔沒有提到'請求()'方法在任何地方,所以你從哪裏得到的呢? – Cody
我想應該使用Request模塊,因爲在文檔中它將原始html代碼傳遞給'parse'函數。 Request模塊已經包含在您的nodejs配置中([doc](https://github.com/request/request)),它允許您獲取網頁的源代碼。 從技術上講,將源代碼存儲在內存中,可以使用文檔中報告的'parse'函數。 –