@SuppressWarnings("resource")
Scanner scan = new Scanner(in, "UTF-8");
scan.useDelimiter("\\n");
+ boolean started = false;
while (scan.hasNext()) {
String line = scan.next();
- if (line.contains("story_category") && !line.contains("title=")) {
- int pos = line.indexOf('>');
- if (pos >= 0) {
- line = line.substring(pos + 1);
- pos = line.indexOf('<');
- if (pos >= 0) {
- line = line.substring(0, pos);
- }
+
+ if (!started) {
+ started = line.contains("\"story_container\"");
+ }
+
+ if (started && line.contains("class=\"tag-")) {
+ if (line.contains("index.php")) {
+ break; // end of *this story* tags
}
- line = line.trim();
- if (!tags.contains(line)) {
- tags.add(line);
+ String keyword = "title=\"";
+ Scanner tagScanner = new Scanner(line);
+ tagScanner.useDelimiter(keyword);
+ if (tagScanner.hasNext()) {
+ tagScanner.next();// Ignore first one
+ }
+ while (tagScanner.hasNext()) {
+ String tag = tagScanner.next();
+ if (tag.contains("\"")) {
+ tag = tag.split("\"")[0];
+ tag = StringUtils.unhtml(tag).trim();
+ if (!tag.isEmpty() && !tags.contains(tag)) {
+ tags.add(tag);
+ }
+ }
}
+ tagScanner.close();
}
}
break;
}
- if (line.startsWith("<a href=")) {
+ if (line.startsWith("<a href=")
+ || line.contains("class=\"chapter-title\"")) {
// Chapter name
String name = line;
int pos = name.indexOf('>');