Using JSoup to parse a html string with Clojure, the source as the following
Dependencies
:dependencies [[org.clojure/clojure "1.10.1"]
[org.jsoup/jsoup "1.13.1"]]
Source code
(require '[clojure.string :as str])
(def HTML (str "<html><head><title>Website title</title></head>
<body><p>Sample paragraph number 1 </p>
<p>Sample paragraph number 2</p>
</body></html>"))
(defn fetch_html [html]
(let [soup (Jsoup/parse html)
titles (.title soup)
paragraphs (.getElementsByTag soup "p")]
{:title titles :paragraph paragraphs}))
(fetch_html HTML)
Expected result
{:title "Website title",
:paragraph ["Sample paragraph number 1"
"Sample paragraph number 2"]}
Unfortunately, the result is not as expected
user ==> (fetch_html HTML)
{:title "Website title", :paragraph []}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…