请帮帮我。我使用了一个 jsoup lib 及其方法hasClass
。为什么Cur
返回“无!”?源页面:
<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;