Created
January 14, 2011 17:09
-
-
Save tototoshi/779897 to your computer and use it in GitHub Desktop.
はてなDiaryからサマリをとってくる
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
import scala.io.Source | |
import scala.xml.XML | |
import java.net.URL | |
case class Entry(title: String, link: URL) | |
val rssURL = "http://d.hatena.ne.jp/tototoshi/rss" | |
val src = Source.fromURL(rssURL) | |
try { | |
val xml = XML.loadString(src.getLines.mkString) | |
val items = xml \\ "item" | |
val entries = items.map(x => Entry((x \ "title").text, new URL((x \ "link").text))) | |
entries.foreach(println) | |
} catch { | |
case e: Exception => println("Network Error") | |
} finally { | |
src.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment