[英]How to extract and store in a string array the text between <strong> and <br> that are inside <p> tag having no html code(i.e etc) in it
[英]How can I download a complete webpage with java without having “ ” replace parts of the HTML code?
我一直在編寫一些網站代碼,並將HTML代碼復制到文本文件中。 問題是某些代碼被替換為“&nbsp”。 這是我正在使用的代碼:
public void addRecords() throws IOException{
URL google = new URL("Insert Website Here");
BufferedReader in = new BufferedReader(
new InputStreamReader(google.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
System.out.println(inputLine);
z.format("%s \n ", (inputLine));
}
in.close();
}
選項2
有許多形式為&...;
HTML實體&...;
在瀏覽器中顯示為特殊字符。 您甚至可以使用免費的數字,字符代碼: &8233;
。
有一個具有類似unescape功能的Apache庫公共語言 :
html = StringEscapeUtils.unescapeHtml4(html);
您可以嘗試如下操作:
System.out.println(inputLine.replaceAll(" "," "));
OBS >請注意,您的HTML頁面可能會包含其他字符轉義符,因此此解決方案不太好重用。
您可以參考本文中在此處看到的common lang Apache項目: 用Java中的等效字符替換HTML代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.