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?

PuercoPop
  • 6,707
  • 4
  • 30
  • 40

1 Answers1

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])
Daniel Neal
  • 4,165
  • 2
  • 20
  • 34
  • When I try to parse the response with html-snippet I get an arity exception https://gist.github.com/PuercoPop/2035343d5af8e0ecfb1d It is an ajax request so it is not complete html, is there a problem with that? – PuercoPop Jul 25 '13 at 20:57
  • Btw the response is pretty short, an option list: https://gist.github.com/PuercoPop/d80b05a0fc6afd5b8a39 – PuercoPop Jul 25 '13 at 21:01
  • 1
    Interesting. When I parse your option list with `(select (html-snippet ) [: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... – Daniel Neal Jul 26 '13 at 05:42
  • I see my mistake I was doing snippet instead of html snippet! – PuercoPop Jul 26 '13 at 07:27