1
try {
String url = "http://www.billboard.com/charts/artist-100";
String urlFound;
String closing = ")";
String start = "h";
Document doc = Jsoup.connect(url).get();
Elements urls = doc.getElementsByClass("chart-row__image");
for (Element u : urls) {
urlFound = u.attr("style");
String sub = urlFound.substring(urlFound.indexOf(start), urlFound.indexOf(closing));
System.out.println(sub);
//Log.d("URLS,", attr.substring(attr.indexOf("http://"), attr.indexOf(")")));
}
}
catch(IOException ex){
}
我試過幾次調試,但我不斷收到錯誤,Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
我不知道爲什麼會發生這種情況嗎?有人能告訴我什麼可能是錯的嗎?獲取索引JSOUP不工作