0

Ребят, простите за вопрос, я новичок совсем. Не нашел ответа у гугла, поэтому пишу тут. Задача стояла в том, чтобы получить данные с этой таблицы яндекс расписания https://voronezhvokzal.ru/raspisanie-poezdov/

Для этого я использовал API яндекса. Вот мой код:

import requests
    
    
url = ("https://api.rasp.yandex.net/v3.0/schedule/?apikey=TOKEN&station=s2014001&transport_types=train&direction=arrival&date=2021-01-13")
res = requests.get(url)
print(res.text)

Проблема заключается в том, что он мне выдал огромный объем данных в формате Json. В запросе я указал все, что мне нужно, но все равно выводятся просто все данные, отсортировать в самом запросе не вышло. Мне нужны данные только с этой таблицы в нынешний момент, но он выдал данные за все будущие даты - минуя мою сортировку. Делал все по документации яндекса. Вот ссылка на документ

Подскажите пожалуйста, как получить только мою таблицу из этого файла?
Простите за много текса, я не знаю, можно ли такое постить..

Вот, что мне выдал запрос:

{
  "pagination": {
    "total": 16,
    "limit": 100,
    "offset": 0
  },
  "schedule": [
    {
      "except_days": null,
      "arrival": "2021-01-12T23:22:00+03:00",
      "thread": {
        "uid": "382S_6_2",
        "title": "Грозный — Москва",
        "number": "382С",
        "short_title": "Грозный — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "11, 13, 15, 17, 19 января, 29 марта, 3, 5, 7, 9, 11, 29 апреля, 1, 3, 5, 7, 9, 11, 13, 15 мая, …",
      "stops": "",
      "departure": "2021-01-13T00:28:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T00:20:00+03:00",
      "thread": {
        "uid": "123N_14_2",
        "title": "Новосибирск — Белгород",
        "number": "123Н",
        "short_title": "Новосибирск — Белгород",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 января, 2, 4, 6, 8, 10, 12, 14, 16, 18 февраля, …",
      "stops": "",
      "departure": "2021-01-13T02:00:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T03:12:00+03:00",
      "thread": {
        "uid": "471M_1_2",
        "title": "Москва — Адлер",
        "number": "471М",
        "short_title": "Москва — Адлер",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "ежедневно по 13.01, кроме 05.01, 06.01, 08.01",
      "stops": "",
      "departure": "2021-01-13T03:48:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T06:48:00+03:00",
      "thread": {
        "uid": "034S_1_2",
        "title": "Москва — Владикавказ",
        "number": "034С",
        "short_title": "Москва — Владикавказ",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "ежедневно по 15.01",
      "stops": "",
      "departure": "2021-01-13T07:23:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": null,
      "thread": {
        "uid": "737ZH_4_2",
        "title": "Воронеж — Москва",
        "number": "737Ж",
        "short_title": "Воронеж — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "ежедневно",
      "stops": "",
      "departure": "2021-01-13T07:33:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T07:12:00+03:00",
      "thread": {
        "uid": "146YE_4_2",
        "title": "Москва — Назрань",
        "number": "146Э",
        "short_title": "Москва — Назрань",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "13, 15, 17, 19, 21, 23, 25, 27, 29, 31 января, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 февраля, …",
      "stops": "",
      "departure": "2021-01-13T07:55:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T11:25:00+03:00",
      "thread": {
        "uid": "374M_3_2",
        "title": "Смоленск — Симферополь",
        "number": "374М",
        "short_title": "Смоленск — Симферополь",
        "carrier": {
          "code": 63438,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "Гранд Сервис Экспресс (Таврия)"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "13, 17 января, 1, 3, 7, 9, 13, 15, 19, 21, 25, 27 мая, 1, 3, 7, 9, 13, 15, 19, 21 июня, …",
      "stops": "",
      "departure": "2021-01-13T12:15:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T12:14:00+03:00",
      "thread": {
        "uid": "035A_0_2",
        "title": "Санкт-Петербург — Адлер",
        "number": "035А",
        "short_title": "Санкт-Петербург — Адлер",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "12, 13, 14, 15, 16, 17, 18 января, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 февраля, …",
      "stops": "",
      "departure": "2021-01-13T12:55:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T14:18:00+03:00",
      "thread": {
        "uid": "036S_4_2",
        "title": "Адлер — Санкт-Петербург",
        "number": "036С",
        "short_title": "Адлер — Санкт-Петербург",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "только 12, 13, 14, 15, 16, 17, 18, 19 января, 12, 13 февраля",
      "stops": "",
      "departure": "2021-01-13T14:57:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T15:08:00+03:00",
      "thread": {
        "uid": "109S_4_2",
        "title": "Анапа — Москва",
        "number": "109С",
        "short_title": "Анапа — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "чт, сб по 13.01, а ещё 05.01, 11.01, 13.01",
      "stops": "",
      "departure": "2021-01-13T15:57:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": null,
      "thread": {
        "uid": "739ZH_1_2",
        "title": "Воронеж — Москва",
        "number": "739Ж",
        "short_title": "Воронеж — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "ежедневно",
      "stops": "",
      "departure": "2021-01-13T16:21:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T19:02:00+03:00",
      "thread": {
        "uid": "306S_4_2",
        "title": "Сухум — Москва",
        "number": "306С",
        "short_title": "Сухум — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "13, 17 января, 28, 29, 30 апреля, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 мая, …",
      "stops": "",
      "departure": "2021-01-13T19:37:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": null,
      "thread": {
        "uid": "025V_2_2",
        "title": "Воронеж — Москва",
        "number": "025В",
        "short_title": "Воронеж — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "13, 14, 15, 16, 17, 18, 19, 21, 24, 28, 31 января, 4, 7, 11, 14, 18, 21, 25, 28 февраля, 4 марта, …",
      "stops": "",
      "departure": "2021-01-13T20:30:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T20:06:00+03:00",
      "thread": {
        "uid": "033S_12_2",
        "title": "Владикавказ — Москва",
        "number": "033С",
        "short_title": "Владикавказ — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "ежедневно по 15.01",
      "stops": "",
      "departure": "2021-01-13T20:55:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-13T20:46:00+03:00",
      "thread": {
        "uid": "145S_7_2",
        "title": "Назрань — Москва",
        "number": "145С",
        "short_title": "Назрань — Москва",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "13, 15, 17, 19, 21, 23, 25, 27, 29, 31 января, 2, 5, 7, 9, 11, 13, 15, 17, 19, 21 февраля, …",
      "stops": "",
      "departure": "2021-01-13T21:28:00+03:00",
      "terminal": null,
      "platform": ""
    },
    {
      "except_days": null,
      "arrival": "2021-01-14T01:24:00+03:00",
      "thread": {
        "uid": "382YA_10_2",
        "title": "Москва — Грозный",
        "number": "382Я",
        "short_title": "Москва — Грозный",
        "carrier": {
          "code": 112,
          "codes": {
            "icao": null,
            "sirena": null,
            "iata": null
          },
          "title": "РЖД/ФПК"
        },
        "transport_type": "train",
        "vehicle": null,
        "transport_subtype": {
          "color": null,
          "code": null,
          "title": null
        },
        "express_type": null
      },
      "is_fuzzy": false,
      "days": "14, 16, 18, 20, 22, 24, 26, 28, 30 января, 1, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 февраля, …",
      "stops": "",
      "departure": "2021-01-14T02:09:00+03:00",
      "terminal": null,
      "platform": ""
    }
  ],
  "station": {
    "code": "s2014001",
    "title": "Воронеж-1",
    "station_type": "station",
    "popular_title": "",
    "short_title": "",
    "transport_type": "train",
    "station_type_name": "станция",
    "type": "station"
  },
  "date": "2021-01-13",
  "interval_schedule": [],
  "event": "departure"
}
3
  • 1
    тут все поезда, проходящие 2021-01-13 через станцию s2014001... в чем ошибка?
    – Jack_oS
    13 янв 2021 в 15:44
  • Я не понимаю как вывести мне только номер поезда, направление и время. Мне нужны только эти данные, как в таблице.
    – yOz
    13 янв 2021 в 15:48
  • как со словарями: for train in data['schedule']: print(f'title {train["title"]}') и т.д...
    – Jack_oS
    13 янв 2021 в 15:56

1 ответ 1

2

Если вы хотите вывести только номер поезда, направление и время, то вам нужно сделать так:

import json
import requests

link = "Здесь вставьте вашу ссылку"
r = requests.get(link)
trains = json.loads(r.text)

for train in trains["schedule"]:
    print(f"Отправка в {train['arrival']}")
    print(f"Номер поезда: {train['thread']['number']}")
    print(f"Направление: {train['thread']['title']}\n")
3
  • in trains['schedule']:
    – Jack_oS
    13 янв 2021 в 15:57
  • Спасибо за замечание, не заметил, когда писал :D
    – mazzz3r
    13 янв 2021 в 15:57
  • спасибо вам большое!
    – yOz
    13 янв 2021 в 16:19

Ваш ответ

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

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