public
Created

Downloader + Parser implementation

  • Download Gist
Speedometer.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package com.czechscala.blank
 
import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.html.HtmlPage
 
object Speedometer extends App {
val downloader = new HttpDownloader("http://www.dsl.sk/speedmeter.php?id=speed_test")
println (downloader.download())
}
 
abstract class Downloader {
def download() : Option[String]
}
 
class HttpDownloader(uri: String) extends Downloader {
private val webclient: WebClient = new WebClient()
def download() : Option[String] = {
val page: HtmlPage = webclient.getPage(uri)
//val out = new PrintWriter( new FileWriter("""D:\output.html"""))
val result = page.asXml()
val regex = """(\d+\.\d+) Kbps""".r
val speed = regex.findFirstIn(result)
speed
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.