From 93a0320b6f9693b5aaf8c645bc6572634da580b6 Mon Sep 17 00:00:00 2001 From: mavlonerkinboev Date: Sat, 24 Jul 2021 14:01:33 +0500 Subject: sixteenth commit --- src/main/java/files/Parser.java | 102 +++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 21 deletions(-) (limited to 'src/main/java/files/Parser.java') diff --git a/src/main/java/files/Parser.java b/src/main/java/files/Parser.java index 4d7f863..6433297 100644 --- a/src/main/java/files/Parser.java +++ b/src/main/java/files/Parser.java @@ -1,5 +1,6 @@ package files; +import com.pengrad.telegrambot.request.SendVideo; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -15,47 +16,78 @@ public class Parser { } public static Anime[] getAnimeAtMainMenu(String page) throws IOException { - Element animeList = Parser.getPage(page).select("div[class=animes-container-list]").first(); + Element animeList = Parser.getPage(page).select("div[id=dle-content]").first(); assert animeList != null; - 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"); - 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]"); - Elements urlsTemp = animeList.select("div[class=h5 font-weight-normal mb-1]").select("a"); + Elements namesTemp = animeList.select("div[class=th-title]"); +// Elements descriptionsTemp = animeList.select("div[class=description d-none d-sm-block]"); +// Elements yearsTemp = animeList.select("span[class=anime-year mb-2]").select("a"); +// Elements genresTemp = animeList.select("span[class=anime-genre d-none d-sm-inline]").select("a[class=mb-2 text-link-gray text-underline]"); + Elements seriesTemp = animeList.select("div[class=th-title]"); + Elements ratingsTemp = animeList.select("div[class=th-rating]"); + Elements imagesTemp = animeList.select("div[class=th-img img-resp-vert img-fit]"); + Elements urlsTemp = animeList.select("div[class=th-itemb]").select("a[class=th-in]"); byte countOfAnime = (byte) namesTemp.size(); ArrayList names = new ArrayList<>(); for (Element name : namesTemp) { - names.add(Jsoup.parse(String.valueOf(name)).text()); + String text = Jsoup.parse(String.valueOf(name)).text(); + int start = 0; + int end = text.indexOf(" ["); + char[] dst = new char[end - start]; + text.getChars(start, end, dst, 0); + names.add(String.valueOf(dst)); } - ArrayList descriptions = new ArrayList<>(); - for (Element description : descriptionsTemp) { - descriptions.add(Jsoup.parse(String.valueOf(description)).text()); +// ArrayList descriptions = new ArrayList<>(); +// for (Element description : descriptionsTemp) { +// descriptions.add(Jsoup.parse(String.valueOf(description)).text()); +// } + +// ArrayList years = new ArrayList<>(); +// for (Element year : yearsTemp) { +// years.add(Jsoup.parse(String.valueOf(year)).text()); +// } + + ArrayList series = new ArrayList<>(); + for (Element oneSeries : seriesTemp) { + String text = oneSeries.toString(); + int start = text.indexOf("из ") + 3; + if (start == 2) start = text.indexOf("ИЗ ") + 3; + int end = text.indexOf("]"); + if (start == 2) { + start = text.indexOf("[") + 1; + end = text.indexOf(" по") + 1; + } + char[] dst = new char[end - start]; + text.getChars(start, end, dst, 0); + if (String.valueOf(dst).equals("ххх")) { + start = text.indexOf("[") + 1; + end = text.indexOf(" из") - 1; + } + series.add(String.valueOf(dst)); } - ArrayList years = new ArrayList<>(); - for (Element year : yearsTemp) { - years.add(Jsoup.parse(String.valueOf(year)).text()); + ArrayList ratings = new ArrayList<>(); + for (Element rating : ratingsTemp) { + ratings.add(Jsoup.parse(String.valueOf(rating)).text()); } ArrayList images = new ArrayList<>(); for (Element image : imagesTemp) { String text = image.toString(); - int start = text.indexOf("data-original=") + 15; - int end = text.indexOf(">") - 1; + int start = text.indexOf("data-src=\"") + 11; + int end = text.indexOf(".jpg") + 4; char[] dst = new char[end - start]; text.getChars(start, end, dst, 0); - images.add(String.valueOf(dst)); + images.add("https://anime.anidub.life/" + String.valueOf(dst)); } ArrayList urls = new ArrayList<>(); for (Element url : urlsTemp) { String text = url.toString(); - int start = text.indexOf("\"") + 1; - int end = text.indexOf(">") - 1; + int start = text.indexOf("href=\"") + 6; + int end = text.indexOf("\">"); char[] dst = new char[end - start]; text.getChars(start, end, dst, 0); urls.add(String.valueOf(dst)); @@ -63,7 +95,7 @@ public class Parser { Anime[] anime = new Anime[countOfAnime]; for (int i = 0; i < countOfAnime; i++) { - anime[i] = new Anime(names.get(i), descriptions.get(i), null, years.get(i), images.get(i), urls.get(i)); + anime[i] = new Anime(names.get(i), null, null, null, series.get(i), ratings.get(i), images.get(i), urls.get(i)); } return anime; @@ -75,6 +107,9 @@ public class Parser { Elements namesTemp = animeList.select("div[class=h5 font-weight-normal mb-2 card-title text-truncate]").select("a"); Elements descriptionsTemp = animeList.select("div[class=anime-small-description read-more-container]"); Elements yearsTemp = animeList.select("span[class=anime-year]").select("a"); + Elements seriesTemp = animeList.select("div[class=th-title]"); + Elements maxSeriesTemp = animeList.select("div[class=th-title]"); + Elements ratingsTemp = animeList.select("div[class=th-rating]"); Elements imagesTemp = animeList.select("div[class=anime-grid-lazy lazy]"); Elements urlsTemp = animeList.select("div[class=h5 font-weight-normal mb-2 card-title text-truncate]").select("a"); @@ -95,6 +130,31 @@ public class Parser { years.add(Jsoup.parse(String.valueOf(year)).text()); } + ArrayList series = new ArrayList<>(); + for (Element oneSeries : seriesTemp) { + String text = oneSeries.toString(); + int start = text.indexOf("[") + 1; + int end = text.indexOf(" из"); + char[] dst = new char[end - start]; + text.getChars(start, end, dst, 0); + series.add(String.valueOf(dst)); + } + + ArrayList maxSeries = new ArrayList<>(); + for (Element oneMaxSeries : maxSeriesTemp) { + String text = oneMaxSeries.toString(); + int start = text.indexOf("из ") + 1; + int end = text.indexOf("]"); + char[] dst = new char[end - start]; + text.getChars(start, end, dst, 0); + maxSeries.add(String.valueOf(dst)); + } + + ArrayList ratings = new ArrayList<>(); + for (Element rating : ratingsTemp) { + ratings.add(Jsoup.parse(String.valueOf(rating)).text()); + } + ArrayList images = new ArrayList<>(); for (Element image : imagesTemp) { String text = image.toString(); @@ -117,7 +177,7 @@ public class Parser { Anime[] anime = new Anime[countOfAnime]; for (int i = 0; i < countOfAnime; i++) { - anime[i] = new Anime(names.get(i), null, null, years.get(i), images.get(i), urls.get(i)); + anime[i] = new Anime(names.get(i), null, null, years.get(i), series.get(i), ratings.get(i), images.get(i), urls.get(i)); } return anime; -- cgit v1.2.3