여기에 두 가지 문제가 있습니다.누군가이 코드의 기능을 설명 할 수 있습니까
다음 코드 블록은 혼란 스럽습니다. 주로 코드가 기본에서 무엇을하는지 정확히 알지 못합니다. 방금 튜토리얼에서 복사했는데, 원하는대로 할 것 같습니다. 누군가가 비트로 설명 할 수 있다면 정말 도움이 될 것입니다.
두 번째 문제점은 ArrayIndexOutOfBounds
오류가 발생하는 이유를 모르겠다는 것입니다. 이유는 이해할 수 없기 때문일 수 있습니다. 정말 명확한 설명이 필요합니다.
try {
Document searchLink = Jsoup.connect("https://www.google.com.ng/search?dcr=0&source=hp&ei=5-cIWuZ30cCwB7aUhrAN&q=" + URLEncoder.encode(searchValue, encoding))
.userAgent("Mozilla/5.0").get();
String websiteLink = searchLink.getElementsByTag("cite").get(0).text();
//we are setting the value for the action "titles" in the wikipedia API with our own article title
//we use the string method replaceAll() to remove the title of the article from the wikipedia URL that we generated from google
//
String wikiAPItoSearch = "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles="
+ URLEncoder.encode(websiteLink.replaceAll("https://en.wikipedia.org/wiki/", ""),encoding);
System.out.println(wikiAPItoSearch);
//extraction of textfiles
//from this point till down i cant really grab what is happening
HttpURLConnection httpconn = (HttpURLConnection) new URL(wikiAPItoSearch).openConnection();
httpconn.addRequestProperty("userAgent", "Mozilla/5.0");
BufferedReader bf = new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
//read line by line
String response = bf.lines().collect(Collectors.joining());
bf.close();
///it returns ArrayIndexOutOfBounds here
String result = response.split("\"extract\":\"")[1];
System.out.println(result);
} catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
}
응답 변수를 콘솔에 출력하고 실제로 추출한 내용이 있는지 확인하려고하지 마십시오 : ":" 'word – johnII