【问题标题】:Parsing snippets of html with enlive使用 enlive 解析 html 片段
【发布时间】:2023-03-09 05:15:02
【问题描述】:

为什么下面的sn-p不起作用?

(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 数据结构或类似的东西?

【问题讨论】:

    标签: clojure web-scraping enlive


    【解决方案1】:

    是的 - 您可以使用 html/html-snippet 将原始 html 字符串转换为 enlive 可以使用的东西, 或 html/html-resource 使用整个 html 文件。

    尝试以下方法:

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

    【讨论】:

    • 当我尝试使用 html-sn-p 解析响应时,我得到一个 arity 异常 gist.github.com/PuercoPop/2035343d5af8e0ecfb1d 这是一个 ajax 请求,所以它不是完整的 html,有什么问题吗?跨度>
    • 顺便说一句,响应很短,一个选项列表:gist.github.com/PuercoPop/d80b05a0fc6afd5b8a39
    • 有趣。当我使用(select (html-snippet &lt;option-list&gt;) [: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...
    • 我发现我的错误是我在做 sn-p 而不是 html sn-p!
    猜你喜欢
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 2014-02-18
    • 2013-01-04
    • 2011-01-27
    • 2012-09-14
    • 1970-01-01
    相关资源
    最近更新 更多