anchor tag count

master
Jason Staten 5 years ago
parent 4af35a5b04
commit 864aab29fe

@ -7,28 +7,34 @@ import akka.util.Timeout;
import scala.io.Source import scala.io.Source
import scala.concurrent.duration._; import scala.concurrent.duration._;
import scala.concurrent.{Await, ExecutionContext, Future} import scala.concurrent.{Await, ExecutionContext, Future}
import scala.xml.XML;
case class Get(url : String) case class Get(url : String)
object Fetch { object Fetch {
def getPageSize(url: String) = Source.fromURL(url).mkString.length() def getPageSize(url: String) = Source.fromURL(url).mkString.length()
def getLinks(url: String) = {
val content = Source.fromURL(url).mkString;
"<a".r.findAllMatchIn(content).length
}
} }
class PageLoader extends Actor { class PageLoader extends Actor {
def receive: Actor.Receive = { def receive: Actor.Receive = {
case Get(url) => sender ! Fetch.getPageSize(url) case Get(url) => sender ! Fetch.getLinks(url)
} }
} }
object LoadPages extends App { object LoadPages extends App {
val system = ActorSystem("ActOne") val system = ActorSystem("ActOne")
val urls = List( val urls = List(
"http://www.amazon.com", "https://www.orbit.fm",
"http://jxs.me", "https://jxs.me",
"http://www.example.com", "https://www.example.com",
"http://sdf.org" "https://sdf.org"
) )
@ -41,7 +47,7 @@ object LoadPages extends App {
def getPageSizeSequentially() = { def getPageSizeSequentially() = {
for (url <- urls) { for (url <- urls) {
println("Size for " + url + ": " + Fetch.getPageSize(url)) println("Links for " + url + ": " + Fetch.getLinks(url))
} }
} }
@ -59,5 +65,4 @@ object LoadPages extends App {
timeMethod { getPageSizeSequentially } timeMethod { getPageSizeSequentially }
timeMethod { getPageSizeConcurrently } timeMethod { getPageSizeConcurrently }
} }

Loading…
Cancel
Save