我正在尝试从网页中提取字符串:https://play.google.com/store/apps/details?id=com.bitmango.rolltheballunrollme。我想要的字符串是:<div class="id-app-title" tabindex="0">Roll the Ball™ - slide puzzle</div>
。
我看了https://jsoup.org/cookbook/extracting-data/selector-syntax,我很确定我按照说明操作,但我得到了:
Exception in thread "main" java.lang.NullPointerException
at gaspacho.Gaspacho.getAppTitle(Gaspacho.java:109)
at gaspacho.Gaspacho.alphabetty(Gaspacho.java:94)
at gaspacho.Gaspacho.main(Gaspacho.java:27)
/home/david/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)
这是我正在使用的方法:
public void getAppTitle(String url){
try {
Document document = Jsoup.connect(url).get();
Element appTitleElement = document.select("div.id-app-title" ).first();
String title = appTitleElement.toString();
System.out.println(title);
} catch (IOException e) {
e.printStackTrace();
}
}
您可以给予任何帮助