Can you provide examples of parsing HTML?

后端 未结 29 2645
走了就别回头了
走了就别回头了 2020-11-22 13:49

How do you parse HTML with a variety of languages and parsing libraries?


When answering:

Individual comments will be linked to in answers to questions

29条回答
  •  迷失自我
    2020-11-22 14:42

    Language: Common Lisp
    Library: Closure Html, Closure Xml, CL-WHO

    (shown using DOM API, without using XPATH or STP API)

    (defvar *html*
      (who:with-html-output-to-string (stream)
        (:html
         (:body (loop
                   for site in (list "foo" "bar" "baz")
                   do (who:htm (:a :href (format nil "http://~A.com/" site))))))))
    
    (defvar *dom*
      (chtml:parse *html* (cxml-dom:make-dom-builder)))
    
    (loop
       for tag across (dom:get-elements-by-tag-name *dom* "a")
       collect (dom:get-attribute tag "href"))
    => 
    ("http://foo.com/" "http://bar.com/" "http://baz.com/")
    

提交回复
热议问题