menu
more_vert
Jsoup(二)-- Jsoup查找DOM元素

作者:dayu

title); /** * 2.根据 id获取元素 */ Element element2 = document.getElementById("site_nav_top"); String navTop = element2.text(); System.out.println("座右铭:" + navTop); /** * 3.根据样式获取元素 */ Elements elements3 = document.getElementsByClass("post_item"); System.out.println("============根据样式获取元素============="); for(Element e : elements3){ System.out.println(e.html()); System.out.println("------------------------------"); } /** * 4.根据属性名称来查询DOM */ Elements elements4 = document.getElementsByAttribute("width"); System.out.println("============根据属性名称来查询DOM============="); for(Element e : elements4){ System.out.println(e.toString()); System.out.println("------------------------------"); } /** * 5.根据属性名和属性值来查询DOM */ Elements elements5 = document.getElementsByAttributeValue("target", "_blank"); System.out.println("============ 根据属性名和属性值来查询DOM============="); for(Element e : elements5){ System.out.println(e.toString()); System.out.println("------------------------------"); } } if(response != null){ response.close(); } if(httpClient != null){ httpClient.close(); } }

Jsoup(二)-- Jsoup查找DOM元素

原文地址:http://www.cnblogs.com/xbq8080/p/7523836.html