強大的Java HTML 解析器,jsoup 1.6.2 發布

fmms 12年前發布 | 14K 次閱讀 jsoup

jsoup 是一款 Java 的HTML 解析器,可直接解析某個URL地址、HTML文本內容。它提供了一套非常省力的API,可通過DOM,CSS以及類似于JQuery的操作方法來取出和操作數據。

jsoup的主要功能如下:

  1. 從一個URL,文件或字符串中解析HTML;
  2. 使用DOM或CSS選擇器來查找、取出數據;
  3. 可操作HTML元素、屬性、文本;

jsoup是基于MIT協議發布的,可放心使用于商業項目。
中文版文檔:http://www.baiduhome.net/jsoup/

jsoup 1.6.2 發布了,改版包含很多的 bug 修復,松散的 XML 解析模式,功能調整以及內存的改進。

主要改進內容包括:

 - Added a simplified XML parsing mode, which can usefully parse valid and invalid XML, but does not enforce any HTML document structure or special tag behaviour.

 - Added the optional ability to track errors when tokenising and parsing.
 - Added Jsoup.connect.cookies(Map) method, to set multiple cookies at once, possibly from a prior request.
 - Added Element.textNodes() and Element.dataNodes(), to easily access an element's children text nodes and data nodes.
 - Added an example program that demonstrates how to format HTML as plain-text, and the use of the NodeVisitor interface.
 - Added Node.traverse() and Elements.traverse() methods, to iterate through a node's descendants.
 - Updated Jsoup.connect() so that when requests made as POSTs are redirected, the redirect is followed as a GET.
 - Updated the Cleaner and whitelists to optionally preserve related links in elements, instead of converting them to absolute links.
 - Updated the Cleaner to support custom allowed protocols such as "cid:" and "data:".
 - Updated handling of base href tags, to act on only the first one seen when parsing, to align with modern browsers.
 - Updated Node.setBaseUri(), to recursively set on all the node's descendants.
Bug fixes:
 - Fixed an issue where all HTML parse errors where being tracked as new objects, creating high memory pressure on low-memory devices.
 - Fixed handling of null characters within comments.
 - Tweaked escaped entity detection in attributes to not treat &entity_... as an entity form.
 - Fixed doctype tokeniser to allow whitespace between name and public identifier.
 - Fixed issue where comments within a table tag would be duplicate-fostered into body.
 - Fixed an issue where a spurious byte-order-mark at the start of a document would cause the parser to miss head contents.
 - Fixed an issue where content after a frameset could cause a NPE crash. Now correctly implements spec and ignores the trailing content.
 - Tweaked whitespace checks to align with HTML spec.
 - Tweaked HTML output of closing script and style tags to not add an extraneous newline when pretty-printing.
 - Substantially reduced default memory allocation within Node.outerHtml, to reduce memory pressure when serialising smaller DOMs.

詳情請看官方發行說明:

http://jsoup.org/news/release-1.6.2

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!