3

Изначально я пытался пропарсить сайт translate.ru, все было хорошо, но при парсинге translate.google.ru вылетает ошибка.

Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403, URL=https://translate.google.ru/ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:598) 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)

А вот вот весь код программы

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 ответ 1

3

Проблема решена. Для того что бы все работало надо поключаться через userAgent("/Здесь передаем название браузера/")

1
  • А пример кода бы еще поместить в ответ...
    – m. vokhm
    2 дек 2016 в 6:54

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.