任何人都可以幫助我從html標籤中將文本解壓爲純文本嗎?從xml解析的html標籤之間提取文本
我已經解析了一個XML並獲得一些輸出作爲身體有html標籤現在我想刪除標籤並使用文本。
在此先感謝!!!!
任何人都可以幫助我從html標籤中將文本解壓爲純文本嗎?從xml解析的html標籤之間提取文本
我已經解析了一個XML並獲得一些輸出作爲身體有html標籤現在我想刪除標籤並使用文本。
在此先感謝!!!!
您可以使用HTML解析器像JSoup
例如 HTML是
<div style="height:240px;"><br>test: example<br>test1:example1</div>
可以使用
Document document = Jsoup.parse(html);
Element div = document.select("div[style=height:240px;]").first();
div.html();
嘗試HTML Parser得到的HTML。
如果HTML轉義,即<
而不是<
,則可能必須先解碼。
考慮你的要求,你可以嘗試Jericho HTML Parser
在TextExtractor類請看:
Using the default settings, the source segment: "<div><b>O</b>ne</div><div title="Two"><b>Th</b><script>//a script </script>ree</div>" produces the text "One Two Three"
。
如果你想要做的是從一個字符串中刪除HTML標記,你可以這樣做:
String output = input.replaceAll("(?s)\\<.*?\\>", " ");
謝謝老闆做 – ReNa 2011-04-22 04:12:48
歡迎您:) – 2011-04-22 06:01:09