Initially, I tried to parse the site translate.ru, everything was fine, but when I parse translate.google.ru an error occurs.

Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status = 403, URL = https://translate.google.com/ at org.jsoup.helper.HttpConnection $ Response.execute (HttpConnection.javament98) at org.jsoup.helper.HttpConnection $ Response.execute (HttpConnection. java: 548) at org.jsoup.helper.HttpConnection.execute (HttpConnection.java:235) at org.jsoup.helper.HttpConnection.get (HttpConnection.java:224) at http.RequestDemo.main (RequestDemo.java:14 )

And here is the whole program code

import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; public class RequestDemo { public static void main(String[] args) throws IOException{ Document doc = Jsoup.connect("https://translate.google.ru/").get(); //System.out.println(doc.html()); Elements metaElements = doc.select("span"); //System.out.println(metaElements); } } 

    1 answer 1

    Problem solved. In order for everything to work, you need to connect via userAgent ("/ Here we transfer the name of the browser /")

    • And an example of the code would be placed in response ... - m. vokhm