package files; 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.net.URL; import java.util.ArrayList; public class Parser { public static Document getPage(String url) throws IOException { return Jsoup.parse(new URL(url), 3000); } public static Anime[] getAnimeAtMainMenu(String page) throws IOException { Element animeList = Parser.getPage(page).select("div[class=animes-container-list]").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[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]"); byte countOfAnime = (byte) namesTemp.size(); ArrayList names = new ArrayList<>(); for (Element name : namesTemp) { names.add(Jsoup.parse(String.valueOf(name)).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 images = new ArrayList<>(); 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[] 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)); } return anime; } }