一、类结构
org.jsoup.nodes
Class Document
java.lang.Object
org.jsoup.nodes.Node
org.jsoup.nodes.Element
org.jsoup.nodes.Document
All Implemented Interfaces:
Cloneable
--------------------------------------------------------------------------------
public class Document
extends
Element
一个HTML文档
二、方法
Constructor Summary
Document(String baseUri)
构造函数:根据baseUri创建一个空白HTML文档
Method Summary
Element
body()
获取HTML文档的body内容
Document
clone()
创建一份Document的完整拷贝
Element
createElement(String tagName)
创建一个tagName节点
static Document
createShell(String baseUri)
创建一个空白的整体HTML框架
Element
head()
获取Document的head值
String
nodeName()
获取一个节点的节点名
Document
normalise()
使document正常化
String
outerHtml()
获取节点的HTML
Document.OutputSettings
outputSettings()
Get the document's current output settings.
Document
outputSettings(Document.OutputSettings outputSettings)
Set the document's output settings.
Document.QuirksMode
quirksMode()
Document
quirksMode(Document.QuirksMode quirksMode)
Element
text(String text)
获取节点或者Document的text值
String
title()
获取Document的title值
void
title(String title)
设置Document的title值
三、实例
[java] view plaincopyprint?
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class JsoupDocument {
private static Document doc;
private static Document shell;
public static void main(String[] args) {
try {
doc = Jsoup.connect("http://www.baidu.com").get();
//System.out.println(doc);
//Body();
//Clone();
//CreateElement();
//CreateShell();
//Head();
//NodeName();
//OuterHtml();
//Text("你好");
//Text();
//Title();
Title("伊诺克Eliot");
} catch (Exception e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
}
}
//获取body
private static void Body(){
System.out.println(doc.body());
}
//克隆Document
private static void Clone(){
Document clone = doc.clone();
System.out.println(clone);
}
//创建一个节点,例如:
private static void CreateElement(){
Element e = doc.createElement("div");
System.out.println(e);
}
//创建一个整体框架
/*
输出:
*/
private static void CreateShell(){
shell = Document.createShell("http://www.baidu.com");
System.out.println(shell);
}
//获取Head
/*
* 输出:
*
百度一下,你就知道= obj.setHomePage('http://www.baidu.com/');}
* */
private static void Head(){
Element e = doc.head();
System.out.println(e);
}
//获取节点名
private static void NodeName(){
String name = doc.body().nodeName();
System.out.println(name);
name = doc.body().getElementById("content").nodeName();
System.out.println(name);
name = doc.body().getElementById("content").getElementById("u").nodeName();
System.out.println(name);
}
//获取节点的html
/*
* 输出:
*
搜索设置|
href="https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F"
name="tj_login" id="lb"οnclick="return false;">登录
href="https://passport.baidu.com/v2/?reg®Type=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F"
target="_blank"name="tj_reg" class="reg">注册