Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ScalaWilliam/3e816ad72a65e301729aa8295dac4b2a to your computer and use it in GitHub Desktop.
Save ScalaWilliam/3e816ad72a65e301729aa8295dac4b2a to your computer and use it in GitHub Desktop.
bbc news via jvm
$ jjs -cp $(coursier fetch org.jsoup:jsoup:1.10.1)
var document = org.jsoup.Jsoup.connect("http://www.bbc.com/news").get()
document.select(".title-link__title-text").stream().map(function(item) { return item.text(); }).forEach(print);
document = org.jsoup.Jsoup.connect("http://www.bbc.com/news").get()
document.select(".title-link__title-text").forEach(function(item) { print(item.text()); })
document.select(".title-link__title-text").stream().map(function(item) { return item.text(); }).forEach(print);
document.select(".title-link__title-text").stream().map(lambda x: x.text()).forEach(lambda x: print(x))
$ jython -J-cp $(coursier fetch org.jsoup:jsoup:1.10.1)
>>> import org.jsoup
>>> document = org.jsoup.Jsoup.connect("http://www.bbc.com/news").get()
>>> for item in document.select(".title-link__title-text"):
... print item.text()
$ scala -cp $(coursier fetch org.jsoup:jsoup:1.10.1)
Welcome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.
scala> val document = org.jsoup.Jsoup.connect("http://www.bbc.com/news").get()
scala> import scala.collection.JavaConverters._
import scala.collection.JavaConverters._
scala> document.select(".title-link__title-text").asScala.map(_.text()).foreach(println)
Merry Christmas from the Obamas
~  /usr/local/Cellar/kotlin/1.0.5-2/bin/kotlinc-jvm -cp $(coursier fetch org.jsoup:jsoup:1.10.1)
>>> val document = org.jsoup.Jsoup.connect("http://www.bbc.com/news").get()
>>> document.select(".title-link__title-text").map{t -> t.text()}.forEach{ t -> println(t) };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment