Получение GPS координат почтовых отделений по индексу
Задача: получить по известному индексу почтового отделения, его адрес, GPS координаты и другие данные..
Решение: а просто попарсим страницу почты россии: https://www.pochta.ru/offices, где есть возможность ввода индекса, а в ответ на карте отрисовываються отделения. Чуть нырнув в сетевые запросы, получаем вызов:
|
1 |
https://www.pochta.ru/suggestions/v2/postoffice.find-nearest-by-postalcode-vacancies |
который используется самим сайтом почты для получения данных. На выходе очень приятный для парсинга выход. В общем всё оформил в виде простого скрипта:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php $indexs=file_get_contents("posts.list"); $indexs=explode("\n", $indexs); file_put_contents("res.sql", "", FILE_APPEND | LOCK_EX); foreach ($indexs as $ind) { `wget https://www.pochta.ru/suggestions/v2/postoffice.find-nearest-by-postalcode-vacancies --header='Content-Type:application/json' --post-data '{"postalCode":"$ind","filters":[],"limit":1,"radius":100,"offset":0,"currentDateTime":"2025-10-28T15:10:00"}' -O tmp.tmp`; $js= json_decode(file_get_contents("tmp.tmp")); if ($js!=null){ if (count($js)>0){ $otd=$js[0]; $address=$otd->addressSource; $latitude=$otd->latitude; $longitude=$otd->longitude; $sql="udpate posts set name='Почтовое отделение $ind',latitude='$latitude',longitude='$longitude',address='$address' where index='$ind';\n"; echo $sql; file_put_contents("res.sql", $sql, FILE_APPEND | LOCK_EX); }; }; }; |