【发布时间】:2017-03-01 07:17:37
【问题描述】:
从网站获取页面并在 clojure 中处理 404 重定向的最佳方式是什么。
我使用了 enlive,但它会自动转换页面,我不希望这样做,因为我想将 HTML 存储在数据库中以供将来参考。
(defn fetch-page [url]
(html/html-resource (java.net.URL. url)))
我遇到过slurp 来获取原始 html 内容,但我不知道这是否是从外部网站检索内容的最佳方法。
我遇到的第二个问题是处理 404,最好的处理方法是什么,我的 clojure 程序在遇到 404 时不正常地存在。
代码:
(println (slurp "http://www.google.com/doesnotexists.html"))
输出:
CompilerException java.io.FileNotFoundException: http://www.google.com/doesnotexists.html
【问题讨论】:
标签: clojure