Created
May 14, 2013 19:11
-
-
Save vire/5578617 to your computer and use it in GitHub Desktop.
Downloader + Parser implementation
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
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