-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLExtractor.java
More file actions
41 lines (37 loc) · 1.26 KB
/
Copy pathHTMLExtractor.java
File metadata and controls
41 lines (37 loc) · 1.26 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
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by sm-user on 11.11.2016.
*/
public class HTMLExtractor {
public String extractLinkPresentByHref(String HTMLText, String Name) {
String PATTERN = "(?i)href\\s*=\\s*(\"" + Name + "\"|'"+ Name + "')";
Pattern pattern = Pattern.compile(PATTERN);
Matcher matcher = pattern.matcher(HTMLText);
String link = null;
while (matcher.find()) {
link = matcher.group();
}
return link;
}
public String extractPageTitle(String HTMLText, String Name) {
String PATTERN = "(?i)<title>\\s*(" + Name + ")\\s*</title>";
Pattern pattern = Pattern.compile(PATTERN);
Matcher matcher = pattern.matcher(HTMLText);
String link = null;
while (matcher.find()) {
link = matcher.group();
}
return link;
}
public String extractLinkPresentByName(String HTMLText, String Name) {
String PATTERN = "(?i)<a([^>]+)>\\s*" + Name + "\\s*</a>";
Pattern pattern = Pattern.compile(PATTERN);
Matcher matcher = pattern.matcher(HTMLText);
String link = null;
while (matcher.find()) {
link = matcher.group();
}
return link;
}
}