标签:
/***
Jsoup的选择器真的是很强大,多多尝试会感觉很有意思
*/
public class TestJsoup {
public static void main(String[] args) {
String str = "<a href=\"/2951/\">一汽-大众奥迪-<h1>奥迪Q3</h1></a>";
parse("a",str);
String str1="<div class=\"breadnav fn-left\">当前位置:<a target=\"_self\" href=\"/\">首页</a> > <a target=\"_self\" href=\"/suva/\">紧凑型SUV</a> > <a target=\"_self\" href=\"/2951/\">奥迪Q3</a> > 综述</div>";
parse("div.breadnav.fn-left a:nth-child(3)",str1);
String str2 = "<div class=\"autoseries-info\"><dl><dt>新车指导价:<a>24.98-42.88万</a> <a>(15款车型)</a></dt><dt>二手车价格:<a></a></dt></dl></div>";
parse("div.autoseries-info dt:contains(新车指导价) a:nth-child(1)",str2);
}
private static void parse(String selector,String str) {
Document doc = Jsoup.parse(str);
Elements elements = doc.select(selector);;
String text = elements.text();
System.out.println(text.replaceAll(" ", ""));
}
}
-------------------------------------------------------
jsoup中文帮助文档
http://www.open-open.com/jsoup/selector-syntax.htm
标签:
原文地址:http://my.oschina.net/u/2329222/blog/510012