Parsing snippets of html with enlive
Asked Answered
B

1

8

Why does the following snippet does not work?

(html/select (:body (client/post "http://www.web.onpe.gob.pe/modElecciones/elecciones/elecciones2011/2davuelta/onpe/presidente/extras/provincias.php" {:form-params {"elegido" "010000"}})) [:option])

Do I have to do something with the html-string to turn it into a clojure datastructure first or something like that?

Braunite answered 25/7, 2013 at 20:27 Comment(0)
W
9

Yep - you can use html/html-snippet to turn a raw html string into something enlive can use, or html/html-resource to use an entire html file.

Try the following:

(html/select 
  (html/html-snippet 
    (:body (client/post "<your-website>" {:form-params {"elegido" "010000"}})) 
  [:option])
Writeup answered 25/7, 2013 at 20:44 Comment(4)
When I try to parse the response with html-snippet I get an arity exception gist.github.com/PuercoPop/2035343d5af8e0ecfb1d It is an ajax request so it is not complete html, is there a problem with that?Braunite
Btw the response is pretty short, an option list: gist.github.com/PuercoPop/d80b05a0fc6afd5b8a39Braunite
Interesting. When I parse your option list with (select (html-snippet <option-list>) [:option]), I get ({:tag :option, :attrs {:value ""}, :content ("--seleccionar--")} {:tag :option, :attrs {:value "010100"}, :content ("CHACHAPOYAS")} {:tag :option, :attrs {:value "010200"}, :content ("BAGUA")} ...) I'm using enlive 1.1.1...Writeup
I see my mistake I was doing snippet instead of html snippet!Braunite

© 2022 - 2024 — McMap. All rights reserved.