저는 nodejs를 처음 사용하며 rss 파서를 사용하려고합니다.무작위로 null 속성을 읽을 수 없습니다.
나는 상점 기사에 mongoose를 사용하고 xml을 json으로 변환하기 위해 rss-parser를 사용한다.
왜 그런지 모르겠지만 "임의의 속성을 임의로 읽을 수 없습니다"라는 오류가 있습니다. 코드가 작동하는 경우도 있고, 그렇지 않은 경우도 있습니다.
/* lib require */
var parser = require('rss-parser');
var mongoose = require('mongoose');
/* Mongodb connection*/
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/rss', function(err) {
if (err) { throw err; }
});
/* Schema for mongoose */
var articleSchema = new mongoose.Schema({
title : String,
pubDate : String,
category: String,
date : { type : Date, default : Date.now }
});
var articleModel = mongoose.model('articles', articleSchema);
/* Array of rss to check */
var rssurl = [];
rssurl.push({url: "URL",
webhook: "LINK";,
category : "CATEGORY"});
rssurl.push({url: "URL",
webhook: "LINK",
category: "CATEGORY"});
/* For each feed, I check if the article exist */
rssurl.forEach(function(item) {
parser.parseURL(item.url, function(err, parsed) {
parsed.feed.entries.forEach(function(entry) {
articleModel.find().count(function(err, count){
if (count <= 0) {
console.log("check");
}
})
})
})
})
편집 :
TypeError: Cannot read property 'feed' of null
at ~/node_modules/rss-parser/index.js:192:15
감사합니다. 죄송합니다. 오류 메시지를 잊어 버렸습니다. "TypeError : null의 'feed'속성을 읽을 수 없습니다. 귀하의 대답은 이것에 대해 작동합니까? – irshlisht44
그럴 경우,'parseURL' 가능성이 높습니다. parser.parseURL (item.url, function (err, parsed))에서'err'의 값을 출력 할 수 있습니까? – AnilRedshift
아무 것도 출력하지 않습니다. 직접 오류가 있습니다. – irshlisht44