我正在做一个关于html文档操作的项目.我希望现有的html文档中的正文内容将其修改为新的html.现在我正在使用JDOM.我想在我的编码中使用body元素.因为我在编码中使用了getChild("body").但它将null返回给我的program.But我的html文档有一个body元素.可以有人帮我知道这个问题我是学生?
会很感激指针..
编码:
import org.jdom.Document;
import org.jdom.Element;
public static void getBody() {
SAXBuilder builder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser", true);
org.jdom.Document jdomDocument=builder.build("http://www......com");
Element root = jdomDocument.getRootElement();
//It returns null
System.out.println(root.getChild("body"));
}
Run Code Online (Sandbox Code Playgroud)
请参考这些..我的html的root和childs在控制台中打印...
root.getName():html
SIZE:2
[Element: <head [Namespace: http://www.w3.org/1999/xhtml]/>]
[Element: <body [Namespace: http://www.w3.org/1999/xhtml]/>]
Run Code Online (Sandbox Code Playgroud) 这个问题可能会毫无意义.但是,任何人都可以向我澄清我对这个问题的编码.我正在进行与解析相关的大学项目.所以我在推荐HtmlCleaner.我被这个编码困扰了.
final CleanerProperties props = new CleanerProperties();
final HtmlCleaner htmlCleaner = new HtmlCleaner(props);
final SimpleHtmlSerializer htmlSerializer =
new SimpleHtmlSerializer(props);
// make 10 threads using the same cleaner and the same serializer
for (int i = 1; i <= 10; i++) {
final String url = "http://search.eim.ebay.eu/Art/2-1/?en=100&ep=" + i;
final String fileName = "c:/temp/ebay_art" + i + ".xml";
new Thread(new Runnable() {
public void run() {
try {
TagNode tagNode = htmlCleaner.clean(new URL(url));
htmlSerializer.writeToFile(tagNode, fileName, "utf-8");
} catch (IOException e) { …Run Code Online (Sandbox Code Playgroud)