Skip to content

Instantly share code, notes, and snippets.

@lambdahands
Last active May 21, 2018 22:31
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 lambdahands/949f69a25c25cb4fd953e99942335503 to your computer and use it in GitHub Desktop.
Save lambdahands/949f69a25c25cb4fd953e99942335503 to your computer and use it in GitHub Desktop.
Clojure + Java

Run this script

Call this in your terminal:

$ clj -Sdeps '{:deps {hello {:git/url "https://gist.github.com/lambdahands/949f69a25c25cb4fd953e99942335503" :sha "02b5ca5c86a800829c6f4aeaf0f83ed016cef49c"}}}' -m hello
{:paths ["."]
:deps {org.jsoup/jsoup {:mvn/version "1.11.3"}}} ;; Importing a Java library
(ns hello
(:require [clojure.java.io :as io])
(:import [org.jsoup Jsoup]))
(def html-string (slurp (io/resource "test.html")))
(def parsed-html (Jsoup/parse html-string))
(def foo-elements (.getElementsByClass parsed-html "foo"))
(defn -main []
(doseq [element foo-elements]
(println (.text element))))
<div class="foo">Hello</div>
<div class="foo">World!</div>
<div class="foo">Clojure is dope</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment