diff options
Diffstat (limited to 'src/main/java/files')
-rw-r--r-- | src/main/java/files/App.java | 5 | ||||
-rw-r--r-- | src/main/java/files/Parser.java | 32 |
2 files changed, 36 insertions, 1 deletions
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); + } + } +} |