I am a new to Clojure and enlive.
I have html like this
<SPAN CLASS="f10"><A HREF="value1" title="...." TARGET="detail">....</A></SPAN></DIV><DIV CLASS="p5"><SPAN CLASS="f10"><A HREF="value2" title="..." TARGET="detail">.....</A></SPAN>
I tried this
(html/select (fetch-url base-url) [:span.f10 [:a (html/attr? :href)]]))
but it returns this
({:tag :a,
:attrs
{:target "detail",
:title
"...",
:href
"value1"},
:content ("....")}
{:tag :a,
:attrs
{:target "detail",
:title
"....",
:href
"value2"},
:content
("....")}
What i want is just value1 and value 2 in the output. How can i accomplish it ?
select
returns the matched nodes, but you still need to extract their href
attributes. To do that, you can use attr-values
:
(mapcat #(html/attr-values % :href)
(html/select (html/html-resource "sample.html") [:span.f10 (html/attr? :href)]))