0
請幫助我。我用一個jsoup lib和它的方法hasClass
。爲什麼Cur
返回「無!」?來源頁面:jsoup hasClass返回錯誤結果
<body>
<div class="pagenav" data-role="vbpagenav" data-pagenumber="2" data-totalpages="223" data-address="showthread.php?t=650495&page=102" data-address2="" data-anchor="">
</div>
</body>
我的代碼:
Document doc = null;
String result = "";
try {
doc = Jsoup.connect(params[0]).get();
Elements body = doc.select("body");
/* Navigation */
String Cur = "";
if (body.hasClass("pagenav")) {
Elements Current = body.select("div[data-pagenumber]");
String Cur1 = Current.attr("data-pagenumber");
int cur_page = Integer.parseInt(Cur1);
int next_page = cur_page + 1;
Cur = Integer.toString(next_page);
} else {
Cur = "none!";
}
result = body.html() + Cur;
} catch (IOException e) {
e.printStackTrace();
}
return result;
這就像一個魅力。謝謝 – FARID