2013-07-25 271 views
8

为什么下面的代码片段不起作用?解析HTML代码片段

(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]) 

我需要做一些事情与html的字符串首先变成clojure数据结构或类似的东西?

回答

9

是的 - 你可以使用html/html-snippet将一个原始的html字符串变成有用的东西, 或html/html-resource使用一个完整的html文件。

尝试以下操作:

(html/select 
    (html/html-snippet 
    (:body (client/post "<your-website>" {:form-params {"elegido" "010000"}})) 
    [:option]) 
+0

当我尝试解析与HTML - 摘录的响应,我得到一个例外元数它https://gist.github.com/PuercoPop/2035343d5af8e0ecfb1d是一个Ajax请求,所以它是不是完整的HTML,有没有问题呢? – PuercoPop

+0

顺便说一句,回应是相当短的一个选项列表:https://gist.github.com/PuercoPop/d80b05a0fc6afd5b8a39 – PuercoPop

+1

有趣。当我用'(select(html-snippet )[:option])'解析你的选项列表时,我得到了'({:tag:option,:attrs {:value“”},:content(“--seleccionar- - “)} {:tag:option,:attrs {:value”010100“},:content(”CHACHAPOYAS“)} {:tag:option,:attrs {:value”010200“},:content(”BAGUA“ )} ...)'我使用enlive 1.1.1 ... –