我正在解析一个网页,我可以解析id但不是类..这就是我的意思;我解析整个消息的包装标识:如何在jsoup解析中选择类
protected String getBlogStats() throws Exception {
String result = "";
// get html document structure
Document document = Jsoup.connect(BLOG_URL).get();
// selector query
Elements nodeBlogStats = document.select("div#news_wrapper");
// check results
if(nodeBlogStats.size() > 0) {
// get value
result = nodeBlogStats.get(0).text();
}
// return
return result;
}
和它的作品,我可以显示的一切,但我需要选择此包装内只有H3标签,所以我这样tryied:
protected String getBlogStats() throws Exception {
String result = "";
// get html document structure
Document document = Jsoup.connect(BLOG_URL).get();
// selector query
Elements nodeBlogStats = document.select("div#news_wrapper .news-col-1 h3");
// check results
if(nodeBlogStats.size() > 0) {
// get value
result = nodeBlogStats.get(0).text();
}
// return
return result;
}
news-col-1
是一个类..但活动是空白..有没有另一种方法来编写类与jsoup解析?由于
你可以像这样写getElementsByClassName(“yourclassname”) –
你可以分享你正试图解析的url吗? –
http://www.multiplayer.it –