Created
January 21, 2009 16:51
-
-
Save tjweir/50035 to your computer and use it in GitHub Desktop.
Process HTML in scala
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
| /*From: http://www.nabble.com/More-elegant-way-of-reading-HTML-from-a-URL-than-this--to21576710.html | |
| */ | |
| class URLLineReader(url: String) { | |
| val reader = new java.io.BufferedReader(new java.io.InputStreamReader(new java.net.URL(url).openStream(), "US-ASCII")); | |
| def foldLeft[T](init: T)(f: (T, String) => T): T = reader.readLine match { | |
| case null => init | |
| case line => foldLeft(f(init, line))(f) | |
| } | |
| } | |
| object Main { | |
| def main(args: Array[String]) = println(new URLLineReader("http://www.yahoo.com/").foldLeft("")(_ + _)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment