我正在解析一個網頁,我可以解析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 –