【发布时间】:2012-02-14 09:26:28
【问题描述】:
有一些文件 index.html(以 UTF-8 保存):
<html>
<head></head>
<body>
<h1> THE TITLE </h1>
Please click <a href="url"> here </a>
<br> ... Some text... <br>
Image: <img src="nature.png"/>
<br> ... Some another text... <br>
Image2: <img src="nature2.png" />
</body>
</html>
我需要获取包含在 BODY 标记内的所有文本,对其进行修改并保存。所以我喜欢这样:
File input = new File("html/input.html");
Document doc = Jsoup.parse(input, "UTF-8", "");
Elements body = doc.select("BODY");
//do some manipulations with the data and print it
System.out.println(body.html());
结果是:
?
<h1> THE TITLE </h1> Please click
<a href="url"> here </a>
...
没关系,除了开头的问号。我怎样才能避免它? 当然我可以从结果字符串中删除它)但是我想了解这是怎么回事。
【问题讨论】:
-
?是否真的是 UTF-8 BOM(字节顺序标记)? -
是的,你是对的)。十六进制编辑器告诉它真的是 BOM。
标签: utf-8 html-parsing jsoup