diff options
-rw-r--r-- | build.gradle | 1 | ||||
-rw-r--r-- | src/main/java/files/App.java | 5 | ||||
-rw-r--r-- | src/main/java/files/Parser.java | 32 |
3 files changed, 37 insertions, 1 deletions
diff --git a/build.gradle b/build.gradle index 3f263dd..ba9a8fb 100644 --- a/build.gradle +++ b/build.gradle @@ -15,4 +15,5 @@ dependencies { implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '3.0.1' implementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '3.0.1' implementation group: 'javax.activation', name: 'activation', version: '1.1.1' + implementation group: 'org.jsoup', name: 'jsoup', version: '1.14.1' } diff --git a/src/main/java/files/App.java b/src/main/java/files/App.java index 23bf859..a219d50 100644 --- a/src/main/java/files/App.java +++ b/src/main/java/files/App.java @@ -15,8 +15,11 @@ import java.util.Properties; public class App { public static void main(String[] args) throws IOException { + // Loading properties Properties properties = new Properties(); properties.load(new FileInputStream("app.properties")); + + // Creating telegram bot TelegramBot bot = new TelegramBot(properties.getProperty("telegram_token")); bot.setUpdatesListener(updates -> { @@ -31,7 +34,7 @@ public class App { String username = update.message().from().username(); String date = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new java.util.Date(update.message().date() * 1000L)); if (update.message().chat().lastName() != null) fullName += " " + update.message().chat().lastName(); - System.out.println(update.message().from().firstName() + " " + update.message().chat().lastName()); + bot.execute(new SendMessage(update.message().chat().id(), "Привет!")); User user = new User(telegramId, isBot, fullName, date); diff --git a/src/main/java/files/Parser.java b/src/main/java/files/Parser.java new file mode 100644 index 0000000..486135b --- /dev/null +++ b/src/main/java/files/Parser.java @@ -0,0 +1,32 @@ +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; + +public class Parser { + + public static Document getPage() throws IOException { + String url = "https://jut.su/anime/"; + 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(); + assert animeList != null; + Elements names = animeList.select("div[class=aaname]"); + + for (Element name : names) { + String text = name.toString(); + int start = 22; + int end = text.indexOf("</div>") - 1; + char[] dst = new char[end - start]; + text.getChars(start, end, dst, 0); + System.out.println(dst); + } + } +} |