-
-
Save emlyn/5782682 to your computer and use it in GitHub Desktop.
Extract the text from a webpage using jericho html parser in clojure.
Run with 'lein one-off extract-text.clj filename.html'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#_(defdeps [[net.htmlparser.jericho/jericho-html "3.1"]]) | |
(ns foo.preprocess | |
(:import [java.io File BufferedInputStream FileInputStream] | |
[net.htmlparser.jericho Source TextExtractor HTMLElementName])) | |
(defn my-text-extractor [source] | |
(proxy [TextExtractor] [source] | |
(excludeElement [tag] | |
(= (.getName tag) HTMLElementName/PRE)))) | |
(defn -main [fname] | |
(let [file (java.io.File. fname) | |
source (Source. (BufferedInputStream. (FileInputStream. file))) | |
tex (my-text-extractor source)] | |
(println (str tex)))) | |
(apply -main *command-line-args*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment