日期:2014-05-18 浏览次数:20792 次
private static Document document = null;
public static void main(String[] args) throws Exception{
File input = new File("D:\\xiuxian.html");
int len = 0 ;
document = Jsoup.parse(input, "UTF-8" ,"D:\\");
Element content = document.getElementById("p2");
Elements links = document.getElementsByTag("a");
if(links != null){
for(Element e : links){
String linkHref = e.attr("href"); //获取属性
String linkText = e.text(); //获取文本内容
e.attr("href", "www.sina.cn"); //设置属性
e.text("新浪"); //设置文本内容
System.out.println(linkHref + " = " + linkText);
}
}
}
File input = new File("D\old.html");
PrintWriter writer = new PrintWriter(input,"UTF-8");
doc.body().append("hello") ;
writer.write(doc.html() ) ;
writer.flush();
writer.close();