summaryrefslogtreecommitdiff
path: root/src/main/java/files/Parser.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/files/Parser.java')
-rw-r--r--src/main/java/files/Parser.java70
1 files changed, 61 insertions, 9 deletions
diff --git a/src/main/java/files/Parser.java b/src/main/java/files/Parser.java
index 486135b..6ed7e77 100644
--- a/src/main/java/files/Parser.java
+++ b/src/main/java/files/Parser.java
@@ -7,26 +7,78 @@ import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.URL;
+import java.util.ArrayList;
public class Parser {
- public static Document getPage() throws IOException {
- String url = "https://jut.su/anime/";
+ public static Document getPage(String url) throws IOException {
return Jsoup.parse(new URL(url), 3000);
}
- public static void main(String[] args) throws IOException {
- Element animeList = Parser.getPage().select("div[class=all_anime_content anime_some_margin]").first();
+ public static Anime[] getAnimeAtMainMenu(String page) throws IOException {
+ Element animeList = Parser.getPage(page).select("div[class=animes-container-list]").first();
assert animeList != null;
- Elements names = animeList.select("div[class=aaname]");
+ Elements namesTemp = animeList.select("div[class=h5 font-weight-normal mb-1]").select("a");
+ Elements descriptionsTemp = animeList.select("div[class=description d-none d-sm-block]");
+ Elements yearsTemp = animeList.select("span[class=anime-year mb-2]").select("a[class=text-link-gray text-underline]");
+ Elements genresTemp = animeList.select("span[class=anime-genre d-none d-sm-inline]").select("a[class=mb-2 text-link-gray text-underline]");
+ Elements imagesTemp = animeList.select("div[class=anime-list-lazy lazy]");
- for (Element name : names) {
+ byte countOfAnime = (byte) namesTemp.size();
+
+ ArrayList<String> names = new ArrayList<String>();
+ for (Element name : namesTemp) {
String text = name.toString();
- int start = 22;
- int end = text.indexOf("</div>") - 1;
+ int start = text.indexOf(">") + 1;
+ int end = text.indexOf("</a>");
+ char[] dst = new char[end - start];
+ text.getChars(start, end, dst, 0);
+ names.add(String.valueOf(dst));
+ }
+
+ ArrayList<String> descriptions = new ArrayList<String>();
+ for (Element description : descriptionsTemp) {
+ String text = description.toString();
+ if (text.length() <= 49) {
+ descriptions.add("");
+ continue;
+ }
+ int start = text.indexOf("\n") + 3;
+ int end = text.indexOf("\n</div>");
+ char[] dst = new char[end - start];
+ text.getChars(start, end, dst, 0);
+ descriptions.add(String.valueOf(dst));
+ }
+
+ ArrayList<String> years = new ArrayList<String>();
+ for (Element year : yearsTemp) {
+ String text = year.toString();
+ int start = text.indexOf(">") + 1;
+ int end = text.indexOf("</a>");
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
- System.out.println(dst);
+ years.add(String.valueOf(dst));
}
+
+ ArrayList<String> images = new ArrayList<String>();
+ for (Element image : imagesTemp) {
+ String text = image.toString();
+ int start = text.indexOf("data-original=") + 15;
+ int end = text.indexOf(">") - 1;
+ char[] dst = new char[end - start];
+ text.getChars(start, end, dst, 0);
+ images.add(String.valueOf(dst));
+ }
+
+ Anime[] animes = new Anime[countOfAnime];
+ for (int i = 0; i < countOfAnime; i++) {
+ animes[i] = new Anime(names.get(i), descriptions.get(i), null, years.get(i), images.get(i));
+ }
+
+ return animes;
}
+
+// public static String[] getAnimeNames() throws IOException {
+//
+// }
}