728x90
반응형
https://jsoup.org/cookbook/extracting-data/selector-syntax
Use CSS selectors to find elements: jsoup Java HTML parser
Use CSS selectors to find elements Problem You want to find or manipulate elements using CSS selectors. Solution Use the Element.select(String cssSelector) and Elements.select(String selector) methods: File input = new File("/tmp/input.html"); Document doc
jsoup.org
String crawlingURL = "";
File folder = new File("E:\\zinc\\");
folder.mkdir();
crawlingURL = "https://zinc.docking.org/substances/" + zinc + "/catitems/subsets/annotated/table.html";
File file = new File("E:\\zinc");
BufferedWriter errBw = new BufferedWriter(new FileWriter("E:\\zinc\\err.txt", true));
try{
Document document = Jsoup.connect(crawlingURL).get();
Elements pageCopy = document.getElementsByClass("table table-striped table-condensed table-hover");//class명 입력
FileOutputStream fos = new FileOutputStream(new File(folder + "\\"+ zinc + ".txt"), true);
OutputStreamWriter osw = new OutputStreamWriter(fos);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(pageCopy.toString());
bw.close();
osw.close();
fos.close();
} catch (Exception e){
errBw.write(moleculeSource.getId() + ", " + zinc + "\n");
errBw.flush();
continue;
}
728x90
반응형
'개발일기 > Spring' 카테고리의 다른 글
JPA (Java Persistence API) (0) | 2024.04.30 |
---|---|
application.properties? application.yml? (0) | 2024.04.29 |
Spring Framework (0) | 2024.04.15 |
Gson을 이용한 json 파일 읽기 (0) | 2024.04.10 |