-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex03_ParsingHTML.java
More file actions
46 lines (42 loc) · 1.18 KB
/
ex03_ParsingHTML.java
File metadata and controls
46 lines (42 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cse3040_22;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
public class ex03 {
static ArrayList<String> lines = new ArrayList<String>();
public static void main(String[] args) {
URL url = null;
BufferedReader input = null;
String addr = "http://www.kyobobook.co.kr/bestSellerNew/bestseller.laf";
String line = "";
try {
url = new URL(addr);
input = new BufferedReader(new InputStreamReader(url.openStream()));
while((line=input.readLine()) != null) {
if(line.trim().length() > 0) lines.add(line);
}
input.close();
}catch(Exception e){
e.printStackTrace();
}
int rank = 1;
int status = 0;
for(int i=0;i<lines.size(); i++) {
String l = lines.get(i);
if(status == 0) {
if(l.contains("div class=\"detail\"")) status = 1;
} else if (status == 1) {
if(l.contains("div class=\"title\"")) status = 2;
} else if (status == 2) {
if(l.contains("a href")) {
int begin = l.indexOf("<strong>") + "<strong>".length();
int end = l.indexOf("</strong>");
System.out.println(rank + "��: "+ l.substring(begin,end));
status = 0;
rank++;
}
}
}
}
}