# 解析一個HTML字符串
<div><h2>存在問題</h2>
<p>來自用戶輸入,一個文件或一個網站的HTML字符串,你可能需要對它進行解析并取其內容,或校驗其格式是否完整,或想修改它。怎么辦?jsonu能夠幫你輕松解決這些問題</p>
<h2>解決方法</h2>
<p>使用靜態<code><a title="Parse HTML into a Document." href="http://jsoup.org/apidocs/org/jsoup/Jsoup.html#parse%28java.lang.String%29">Jsoup.parse(String
html)</a></code> 方法或 <code><a title="Parse HTML into a Document." href="http://jsoup.org/apidocs/org/jsoup/Jsoup.html#parse%28java.lang.String,%20java.lang.String%29">Jsoup.parse(String
html, String baseUri)</a></code>示例代碼:</p>
<pre><code>String html = "<html><head><title>First parse</title></head>"
+ "<body><p>Parsed HTML into a doc.</p></body></html>";
Document doc = Jsoup.parse(html);
</code></pre>
<h2>描述</h2>
<p><code><a title="Parse HTML into a Document." href="http://jsoup.org/apidocs/org/jsoup/parser/Parser.html#parse%28java.lang.String,%20java.lang.String%29">parse(String
html, String baseUri)</a></code> 這方法能夠將輸入的HTML解析為一個新的文檔 (Document),參數 baseUri 是用來將相對 URL 轉成絕對URL,并指定從哪個網站獲取文檔。如這個方法不適用,你可以使用 <code><a title="Parse HTML into a Document." href="http://jsoup.org/apidocs/org/jsoup/Jsoup.html#parse%28java.lang.String%29">parse(String
html)</a></code> 方法來解析成HTML字符串如上面的示例。.</p>
<p>只要解析的不是空字符串,就能返回一個結構合理的文檔,其中包含(至少) 一個head和一個body元素。</p>
<p>一旦擁有了一個Document,你就可以使用Document中適當的方法或它父類 <code><a title="A HTML element consists of a tag name, attributes, and child nodes (including text nodes and other elements)." href="http://jsoup.org/apidocs/org/jsoup/nodes/Element.html">Element</a></code>和<code><a title="The base, abstract Node model." href="http://jsoup.org/apidocs/org/jsoup/nodes/Node.html">Node</a></code>中的方法來取得相關數據。</p><br></div>
- Introduction
- 爬蟲相關技能介紹
- 爬蟲簡單介紹
- 爬蟲涉及到的知識點
- 爬蟲用途
- 爬蟲流程介紹
- 需求描述
- Http請求處理
- http基礎知識介紹
- http狀態碼
- httpheader
- java原生態處理http
- URL類
- 獲取URL請求狀態
- 模擬Http請求
- apache httpclient
- Httpclient1
- httpclient2
- httpclient3
- httpclient4
- httpclient5
- httpclient6
- okhttp
- OKhttp使用教程
- 技術使用
- java執行javascript
- 網頁解析
- Xpath介紹
- HtmlCleaner
- HtmlCleaner介紹
- HtmlCleaner使用
- HtmlParser
- HtmlParser介紹
- Jsoup
- 解析和遍歷一個HTML文檔
- 解析一個HTML字符串
- 解析一個body片斷
- 從一個URL加載一個Document
- 從一個文件加載一個文檔
- 使用DOM方法來遍歷一個文檔
- 使用選擇器語法來查找元素
- 從元素抽取屬性,文本和HTML
- 處理URLs
- 示例程序 獲取所有鏈接
- 設置屬性的值
- 設置一個元素的HTML內容
- 消除不受信任的HTML (來防止XSS攻擊)
- 正則表達式
- elasticsearch筆記
- 下載安裝elasticsearch
- 檢查es服務健康