Last active
February 2, 2016 05:01
-
-
Save iorionda/da8c8b4c7df1979e7ece to your computer and use it in GitHub Desktop.
FeedParserの使い方
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var FeedParser = require('feedparser'); | |
var request = require('request'); | |
var feed = 'https://news.google.com/news?output=rss&q='; | |
var query = encodeURI('山岳遭難'); | |
var req = request(feed + query); | |
var feedparser = new FeedParser({}); | |
var items = []; | |
req.on('response', function(res) { | |
this.pipe(feedparser); | |
}); | |
feedparser.on('meta', function(meta) { | |
console.log('=== %s ===', meta.title); | |
}); | |
feedparser.on('readable', function() { | |
var item; | |
while(item = this.read()) { | |
items.push(item); | |
} | |
}); | |
feedparser.on('end', function() { | |
items.forEach(function(item) { | |
console.log('title:' + item.title.split('-')[0].trim()); | |
console.log('from:' + item.title.split('-')[1].trim()); | |
console.log('link:' + item.link.split('url=')[1]); | |
console.log('pubDate:' + item.pubDate); | |
console.log('description:' + item.description.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g,'')); | |
}); | |
}); |
Author
iorionda
commented
Feb 2, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment