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?

1 Answer 1

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])
Sign up to request clarification or add additional context in comments.

4 Comments

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?
Btw the response is pretty short, an option list: gist.github.com/PuercoPop/d80b05a0fc6afd5b8a39
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...
I see my mistake I was doing snippet instead of html snippet!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.