-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.java
More file actions
100 lines (100 loc) · 2.8 KB
/
Search.java
File metadata and controls
100 lines (100 loc) · 2.8 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import javax.swing.DefaultListModel;
import java.net.HttpURLConnection;
import java.io.FileOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.BufferedInputStream;
public class Search extends Thread{
public static DefaultListModel<String> list = new DefaultListModel<>();
private String text = "";
private Links links = new Links("");
public Search(String text) {
this.text = text;
}
public boolean addPDF(String url) {
String link = "";
String html = "";
int von = 0;
int bis = 0;
HttpURLConnection con;
ByteArrayOutputStream baos;
BufferedInputStream in;
try {
html = HTTP.sendGet(url);
while(html.contains("href=\"http")){
von = html.indexOf("href=\"http") + "href=\"".length();
bis = von;
while (bis < html.length() && html.charAt(bis) != '"') {
++bis;
}
link = html.substring(von, bis);
PaperBoy.label.setText("Scanne: " + link);
html = html.replaceFirst("href=\"http", "");
con = HTTP.connect(link);
baos = new ByteArrayOutputStream();
in = new BufferedInputStream(con.getInputStream());
byte[] buffer = new byte[4];
int n;
if ((n = in.read(buffer)) > 0) {
baos.write(buffer,0, n);
}
//in.close();
//baos.close();
//con.disconnect();
byte[] response = baos.toByteArray();
if(response.length == 4 && response[0] == 37
&& response[1] == 80
&& response[2] == 68
&& response[3] == 70) {
if (!list.contains(link)) {
list.addElement(link);
}
return true;
}
}
} catch(Exception e) {
System.out.println(e);
}
return false;
}
public void add(Links html) {
while (links.hasNext()) {
addPDF(links.next());
}
}
public Links nextHTML() {
if (links.getHtml().equals("")) {
try {
links.setHtml(HTTP.sendGet("https://www.base-search.net/Search/Results?lookfor="
+ text + "&type=all&page=1&l=de&oaboost=1&refid=dcpagede"));
} catch(Exception e) {
System.out.println(e);
}
} else {
int bis = links.getHtml().indexOf("\" title=\"weiter\"><img src=\"/interface/images/pfeil_gruen_rechts.png\" alt=\"weiter\" />");
int von = bis;
while (von > 0 && links.getHtml().charAt(von - 1) != '"') {
--von;
}
try {
links.setHtml(HTTP.sendGet(links.getHtml().substring(von, bis).replace("amp;", "")));
} catch(Exception e) {
System.out.println(e);
}
}
return links;
}
public boolean hasNextHTML() {
if (links.getHtml().equals("")) {
return true;
} else {
return links.getHtml().contains("<img src=\"/interface/images/pfeil_gruen_rechts.png\" alt=\"weiter\" />");
}
}
public void run() {
list.clear();
while (hasNextHTML()) {
add(nextHTML());
}
PaperBoy.label.setText("Fertig");
}
}