1

Есть сайт. На нем нужно узнать расписание преподавателей. Я отследил какие данные откуда идут. Значит:

  1. Идёт GET-запрос на http://schedule.npi-tu.ru/ajax/list_prep?term=Алексанян+Г+К. Отсюда мы получаем три параметра. Их значения: KFAK, KKAF, KPERP
  2. Идёт POST-запрос на http://schedule.npi-tu.ru/ajax/print_table и мы получаем уже html код с расписанием.

Проблема в том, что я не знаю, как осуществить это с помощью JSOUP. Я пробовал делать так:

private static String userAgent = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36";

public static void main(String[] args){



        try {
            Connection.Response res = Jsoup.connect("http://schedule.npi-tu.ru/ajax/print_table")
                    .userAgent(userAgent)
                    .method(Connection.Method.POST)
                    .data("KFAK", "A")
                    .data("KKAF", "3")
                    .data("KPREP", "5")
                    .referrer("http://schedule.npi-tu.ru/application/prep")
                    .execute();

            Map<String, String> cookies = res.cookies();

            Document doc2 = Jsoup
                    .connect("http://schedule.npi-tu.ru/application/prep")
                    .userAgent(userAgent)
                    .cookies(cookies)
                    .get();

            s = doc2.html();
            System.out.println(s);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            System.out.println(e.toString());
            tracker = false;
        }
    }

Но из этого ничего не вышло.

1 ответ 1

6

Получить таблицу можно вот так. А дальше с ней можно работать как угодно.

    Document doc = Jsoup.connect("http://schedule.npi-tu.ru/ajax/print_table")
            .data("KFAK", "A")
            .data("KKAF", "3")
            .data("KPREP", "5")
            .post();

    System.out.println(doc.getElementsByTag("tbody"));
1
  • @АндрейСулыз да. расписание выдается в виде html table. 24 дек 2016 в 14:11

Ваш ответ

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

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