Skip to content

Instantly share code, notes, and snippets.

@pbrandiezs
Created June 10, 2021 20:16
Show Gist options
  • Save pbrandiezs/69fbf90d55fef17a852655573f2c42f2 to your computer and use it in GitHub Desktop.
Save pbrandiezs/69fbf90d55fef17a852655573f2c42f2 to your computer and use it in GitHub Desktop.
Count the number of hrefs in a list of url's provided as command line arguments
import java.net.URL
import org.apache.commons.lang3.StringUtils
fun main(args: Array<String>) {
args.forEach {
// val contents = URL("https://www.wikipedia.com").readText()
val contents = URL(it).readText()
val hrefCount = StringUtils.countMatches(contents, "href")
println("$it $hrefCount")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment