I implement a bot telegram for parsing. The proxy works, the bot responds to words, but the parsing does not work as expected and does not display why?

class Main

import org.telegram.telegrambots.ApiContextInitializer; import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.meta.ApiContext; import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; public class Main { // private static String PROXY_HOST = "87.214.0.47" /* proxy host */; // private static Integer PROXY_PORT = 3128 /* proxy port */; public static void main(String[] args) { try { ApiContextInitializer.init(); TelegramBotsApi telegramm = new TelegramBotsApi(); DefaultBotOptions options = ApiContext .getInstance(DefaultBotOptions.class); options.setProxyHost("166.62.83.129"); options.setProxyPort(20333); //Select proxy type: [HTTP|SOCKS4|SOCKS5] (default: NO_PROXY) options.setProxyType(DefaultBotOptions.ProxyType.SOCKS5); telegramm.registerBot(new Bot(options)); } catch (TelegramApiRequestException e) { e.printStackTrace(); } } } 

class bot

 import org.telegram.telegrambots.bots.DefaultBotOptions; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; public class Bot extends TelegramLongPollingBot { KapperBook kapperBook = new KapperBook(); private long chat_id; public Bot(DefaultBotOptions options) { super(options); } public void onUpdateReceived(Update update) { update.getUpdateId(); SendMessage sendMessage = new SendMessage().setChatId(update.getMessage().getChatId()); chat_id = update.getMessage().getChatId(); sendMessage.setText(input(update.getMessage().getText())); try { execute(sendMessage); } catch (TelegramApiException e) { e.printStackTrace(); } } public String getBotUsername() { return "@KupperMSCBot"; } public String getBotToken() { return "787571455:AAFl9vffyhKqLq6ADadWJg2ByzQFMBifcno"; } public String getInfoKapperBook() { String info = kapperBook.getTitle() + "\nΠ›ΠΈΠ³Π° " + kapperBook.getGeners() + "\n\nОписаниС " + kapperBook.getDescription() + "\n\nΠšΠΎΠ»ΠΈΡ‡Π΅ΡΡ‚ΠΎΠ² Π»Π°ΠΉΠΊΠΎΠ²\n" + kapperBook.getOrating_res(); return info; } String input(String msg) { if (msg.contains("Π‘Ρ‚Π°Π²ΠΊΠ°")) { return getInfoKapperBook(); } return msg; } } 

class KapperBook

 import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; import java.io.IOException; public class KapperBook { private Document document; public KapperBook() { connect(); } private void connect() { try { document = Jsoup.connect("https://vprognoze.ru/forecast/pro/").get(); } catch (IOException e) { e.printStackTrace(); } } public String getTitle() { return document.title(); } public String getOrating_res() { // Element element = document.getElementById("orating_res"); // лайки Elements elements = document.getElementsByClass("orating_res"); return elements.text(); } public String getDescription() { Elements elements = document.getElementsByClass("news_box"); //Element element = document.getElementById("news_box"); // описаниС return elements.text(); } public String getGeners() { Elements elements = document.getElementsByClass("championship"); //лига return elements.text(); } } 
  • I apologize for the clumsy question because first time here. The essence of the following implement a telegram bot for parsing. Proxy worker. the bot responds to the words, but the parsing does not and does not display on the screen why? - Ivan Abramov
  • How is it expected and what does it do? Did you use the debugger? Where do you get what you expect? - iksuy 2:49 pm
  • Mar 08, 2019 3:00:23 PM org.apache.http.impl.execchain.RetryExec execute INFO: I / O exception (java.net.SocketException) caught when processing request to {s} -> api.telegram.org : 443 : Connection timed out: connect Mar 08, 2019 3:00:23 PM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {s} -> api.telegram.org TET43 This is such I have an error! - Ivan Abramov

1 answer 1

When you try to connect via Jsoup from the box to the address you specify, an exception flies:

 org.jsoup.HttpStatusException: HTTP error fetching URL. Status=307, URL=https://vprognoze.ru/forecast/pro/ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:435) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410) at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164) at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153) at ua.spoon.Application.main(Application.java:27) 

On en SO there is a question on this topic.

HTTP status code, it’s not a mistake, it’s making a temporary redirect to another page.

Free translation:

HTTP status code 307 is not an error code, but information that the server server is temporarily redirecting to another page.