forked from mkyong/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
48 lines (34 loc) · 1.07 KB
/
Copy pathApp.java
File metadata and controls
48 lines (34 loc) · 1.07 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
package com.mkyong;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
public class App {
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("[Usage] jar -jar find-links.jar <url>");
return;
}
String url = args[0];
for (String link : findLinks(url)) {
System.out.println(link);
}
}
private static Set<String> findLinks(String url) throws IOException {
Document doc = Jsoup.connect(url)
.data("query", "Java")
.userAgent("Mozilla")
.cookie("auth", "token")
.timeout(3000)
.get();
Set<String> links = new HashSet<>();
Elements elements = doc.select("a[href]");
for (Element element : elements) {
links.add(element.attr("href"));
}
return links;
}
}