progs/crawler1.scala
changeset 96 9fcd3de53c06
parent 95 dbe49327b6c5
child 99 91145f6d9b0e
--- a/progs/crawler1.scala	Tue Sep 24 01:12:36 2013 +0100
+++ b/progs/crawler1.scala	Tue Sep 24 01:56:53 2013 +0100
@@ -1,18 +1,11 @@
 import io.Source
 import scala.util.matching.Regex
+import scala.util._
 
 // gets the first ~10K of a page
-def get_page(url: String) : String = { 
-  try {
-    Source.fromURL(url).take(10000).mkString  
-  }
-  catch {
-    case _ : Throwable => {
-      println(s"  Problem with: $url")
-      ""
-    }
-  }
-}
+def get_page(url: String) : String = 
+  Try(Source.fromURL(url).take(10000).mkString) getOrElse 
+    { println(s"  Problem with: $url"); ""}
 
 
 // regex for URLs