Answer the question
In order to leave comments, you need to log in
How to parse Yandex.Maps search results?
Good afternoon!
Can you please tell me how to parse data from an organization's page in Yandex.Maps? In particular, you need to take data on the rating of the organization and the number of reviews from it. I know that there is a certain API at the link https://yandex.ru/maps/api/business/fetchReviews (I found it among the questions on the same portal), but this is not quite right. The reviews themselves are issued there, but you need what I wrote above.
There is one problem - Yandex renders the elements on the page gradually. When you parse it through the Simple HTML DOM, it comes out empty. How can this be bypassed? After all, some script is probably being executed that accesses the link and receives all this data from there. I don't know how to deal with it.
Answer the question
In order to leave comments, you need to log in
Another task: to correctly extract the rating data of the organization. I asked Yandex support how to do this without violating the rules of the platform. Waiting for a response and posting here.
In the meantime, there is a simple solution, to retrieve data using a PHP shortcode:
<?php
function rating_function($atts) {
extract(shortcode_atts(array(
// вставляем ссылку на карточку организации в Яндекс Справочике как есть
"url" => 'https://yandex.ru/maps/org/<---id организации--->',
), $atts));
$content = file_get_contents($url);
// определяем начало необходимого фрагмента кода, до которого мы удалим весь контент
$pos = strpos($content, '<div class="orgpage-reviews-view__rating-score">');
// удаляем все до нужного фрагмента
$content = substr($content, $pos);
// находим конец необходимого фрагмента кода
$pos = strpos($content, '</div>');
// отрезаем нужное количество символов от конца фрагмента
$content = substr($content, 0, $pos);
echo $content;
}
add_shortcode('rating', 'rating_function');
?>
NO WAY.
YOU have already pulled up lovers of freebies.
Because of you, it is no longer possible to use Yandex services - it always shows captcha, which you can’t read.
Moreover, Yandex already gives for free, through api. But no - we turn up our noses, we'd rather rub change in our pockets and spoil everyone around.
Try at least once in your life to do something of your own, and not try to steal someone else's.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question