Skip to content

Instantly share code, notes, and snippets.

@vire
Created May 14, 2013 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vire/5578617 to your computer and use it in GitHub Desktop.
Save vire/5578617 to your computer and use it in GitHub Desktop.
Downloader + Parser implementation
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment