scraper-apis/2gis-parser

PHP client library for scraping 2GIS data (places, reviews, property, jobs) using Apify actors

Maintainers

Package info

github.com/Scraper-APIs/2gis-parser-php

pkg:composer/scraper-apis/2gis-parser

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-02-20 03:43 UTC

This package is auto-updated.

Last update: 2026-02-20 03:43:55 UTC


README

English | Русский

PHP-библиотека для парсинга данных 2ГИС: организации, отзывы, недвижимость, вакансии.

Работает через Apify API — запускает акторы и возвращает типизированные DTO.

Установка

composer require scraper-apis/2gis-parser

Быстрый старт

use TwoGisParser\Client;

$client = new Client('apify_api_ваш_токен');

// Поиск ресторанов в Москве
$places = $client->scrapePlaces(
    query: ['ресторан'],
    location: 'Москва',
    maxResults: 50,
);

foreach ($places as $place) {
    echo "{$place->name}{$place->address}" . PHP_EOL;
    echo "Рейтинг: {$place->rating}, отзывов: {$place->reviewCount}" . PHP_EOL;

    if ($place->hasContactInfo()) {
        echo "Тел: {$place->getFirstPhone()}" . PHP_EOL;
    }
}

Методы

Организации

$places = $client->scrapePlaces(
    query: ['стоматология', 'клиника'],
    location: 'Санкт-Петербург',
    maxResults: 200,
    language: Language::Russian,
    country: Country::Russia,
    options: [
        'filterRating' => 'excellent',      // 4.5+
        'skipClosedPlaces' => true,
        'maxReviews' => 10,                  // подгрузить отзывы
        'filterCardPayment' => true,
    ],
);

Хелперы Place:

$place->hasContactInfo();    // есть телефоны или email
$place->getFirstPhone();     // первый номер телефона или null
$place->getFirstEmail();     // первый email или null
$place->hasWebsite();        // есть ли сайт
$place->getCoordinates();    // ['lat' => float, 'lng' => float] или null

Отзывы

$reviews = $client->scrapeReviews(
    startUrls: ['https://2gis.ru/moscow/firm/70000001057394703'],
    maxReviews: 100,
    maxPlaces: 5,
    reviewsRating: ReviewsRating::Negative,  // только 1-2 звезды
    reviewsSource: ReviewsSource::TwoGis,
);

foreach ($reviews as $review) {
    echo "{$review->authorName}: {$review->rating}/5" . PHP_EOL;

    if ($review->hasOfficialAnswer()) {
        echo "Ответ: {$review->getOfficialAnswerText()}" . PHP_EOL;
    }
}

Хелперы Review:

$review->hasOfficialAnswer();      // есть ли ответ компании
$review->getOfficialAnswerText();  // текст ответа или null
$review->hasPhotos();              // есть ли фото у отзыва
$review->isPositive();             // рейтинг >= 4
$review->isNegative();             // рейтинг <= 2

Недвижимость

$properties = $client->scrapeProperties(
    location: 'Казань',
    maxResults: 500,
    category: PropertyCategory::SaleResidential,
    sort: PropertySort::PriceAsc,
    options: [
        'rooms' => ['2', '3'],
        'priceMax' => 15000000,
        'notFirstFloor' => true,
    ],
);

foreach ($properties as $property) {
    echo "{$property->name}{$property->getPriceFormatted()}" . PHP_EOL;
    echo "{$property->area} м², этаж {$property->floor}" . PHP_EOL;
}

Хелперы Property:

$property->hasImages();         // есть ли фото
$property->getCoordinates();    // ['lat' => float, 'lng' => float] или null
$property->getPriceFormatted(); // "1 500 000 RUB" или null

Вакансии

$jobs = $client->scrapeJobs(
    location: 'Новосибирск',
    maxResults: 300,
    categoryId: '200',       // Разработка
    salaryMin: 80000,
    salaryMax: 250000,
);

foreach ($jobs as $job) {
    echo "{$job->name}{$job->orgName}" . PHP_EOL;
    echo "Зарплата: {$job->salaryLabel}" . PHP_EOL;
}

Хелперы Job:

$job->hasApplyUrl();      // есть ли ссылка для отклика
$job->getCoordinates();   // ['lat' => float, 'lng' => float] или null

Фильтры и перечисления

Enum Значения
Language Auto, Russian, English, Arabic, Kazakh, Uzbek, Kyrgyz, Armenian, Georgian, Azerbaijani, Tajik, Czech, Spanish, Italian
Country Auto, Russia, Kazakhstan, UAE, Uzbekistan, Kyrgyzstan, Armenia, Georgia, Azerbaijan, Belarus, Tajikistan, SaudiArabia, Bahrain, Kuwait, Qatar, Oman, Iraq, Chile, Czechia, Italy, Cyprus
RatingFilter None, Perfect (4.9+), Excellent (4.5+), PrettyGood (4.0+), Nice (3.5+), NotBad (3.0+)
ReviewsRating All, Positive (4-5), Negative (1-2)
ReviewsSource All, TwoGis, Flamp, Booking
PropertyCategory SaleResidential, SaleCommercial, RentResidential, RentCommercial, DailyRent
PropertySort Default, PriceAsc, PriceDesc, AreaAsc, AreaDesc

Конфигурация

use TwoGisParser\Client;
use TwoGisParser\Config;

// Изменить таймаут или базовый URL
$client = new Client('токен', new Config(
    apiToken: 'токен',
    timeout: 600,
));

Обработка ошибок

use TwoGisParser\Exception\ApiException;
use TwoGisParser\Exception\RateLimitException;

try {
    $places = $client->scrapePlaces(query: ['кафе'], location: 'Алматы');
} catch (RateLimitException $e) {
    sleep($e->retryAfter);
    // повторить запрос
} catch (ApiException $e) {
    echo "Ошибка API: {$e->getMessage()}" . PHP_EOL;
}

Требования

См. также

  • Yandex Parser PHP — парсинг Яндекса (организации и отзывы с Яндекс Карт, товары с Яндекс Маркета, объявления с Яндекс Недвижимости)

Лицензия

MIT