.edu 도메인을 통해 크롤링하는 웹 크롤러를 만들고 있습니다. jsoup를 사용하여 앵커 링크 용 HTML 파일을 구문 분석합니다. 그런 다음 중복 된 URL을 갖고 싶지 않기 때문에 링크를 HashSet에 추가합니다. 그러나, 내 HashSet 밖으로 인쇄 할 때 여러 URL이 중복되어 있습니다. HashSet Java의 중복 요소
내가 멤버 함수 내 씨앗 파일에서private Set <String> url = new HashSet<String>();
public void jsoupParse(String htmlFile, String baseUrl){
try{
File input = new File(htmlFile);
Document doc = Jsoup.parse(input, "UTF-8", baseUrl);
Elements links = doc.select("a[href]");
for (Element link : links) {
String linkHref = link.attr("abs:href");
linkHref.trim();
url.add(linkHref);
}
printCollection();
}
catch(IOException e){
e.printStackTrace();
}
}
로 내 세트를 선언, 나는 4 개 URL이, 그래서 나는 4 htmlFiles 있습니다. 내가 인쇄 할 때 나는 659 개의 항목을 얻는다. 아래는 내 출력 샘플입니다. 예를 들어,이 특정 URL은 네 번 인쇄됩니다. http://diversity.mit.edu/diversity-summit-2015/
내 출력 : 자바와 같은 널리 사용되는 잘 확립 된 언어에 대한
http://web.mit.edu/admissions/
http://diversity.mit.edu/
http://newsoffice.mit.edu
http://whereis.mit.edu
http://diversity.mit.edu/diversity-summit-2015/
http://diversity.mit.edu/event/mlk-celebration-2015/
http://mit.edu/site/?ref=mithomepage
http://ki.mit.edu
http://web.mit.edu/athletics/www/
http://twitter.com/mit
http://libraries.mit.edu/
http://web.mit.edu/faculty/
....
http://newsoffice.mit.edu
http://strategiccommunications.ucr.edu/
http://hvrd.me/GmV2x
http://diversity.mit.edu/diversity-summit-2015/
http://ucr.edu/
http://hvrd.me/IaiDY
http://ki.mit.edu
http://stanford.edu/academics/programs
http://news.stanford.edu/news/2015/january/jones-students-econversation-012815.html
http://harvard.edu/#skip
http://campusmap.ucr.edu/?loc=HINHL
출력이 중복 된 것을 보여줄 수 있습니까? – Eran