[英]Java Jsoup button selection
I just want to check whether given element exists or not, I have the following code: 我只想检查给定元素是否存在,我有以下代码:
Document doc = Jsoup.connect("http://www.gsmarena.com/news.php3?iPage=2").get();
Elements button = doc.select("a > pages-next");
if (!button.isEmpty()) {
System.out.println("contains");
} else {
System.out.println("not contains");
}
But it always returns false, here is also the element that I want to check: 但是它总是返回false,这也是我要检查的元素:
There are two issues here: 这里有两个问题:
.pages-next
and not a > pages-next
. 右边的选择器是.pages-next
而不是a > pages-next
。 Use this code - 使用此代码-
Document doc = Jsoup.connect("http://www.gsmarena.com/news.php3?iPage=2")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0")
.get();
Elements button = doc.select(".pages-next");
if (!button.isEmpty()) {
System.out.println("contains");
} else {
System.out.println("not contains");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.