Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created January 14, 2011 17:09
Show Gist options
  • Save tototoshi/779897 to your computer and use it in GitHub Desktop.
Save tototoshi/779897 to your computer and use it in GitHub Desktop.
はてなDiaryからサマリをとってくる
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