Skip to content

Типобезопасные DTO для 2gis через Apify

Notifications You must be signed in to change notification settings

Scraper-APIs/2gis-parser-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2GIS Parser PHP

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,
    ],
);

Отзывы

$reviews = $client->scrapeReviews(
    startUrls: ['https://2gis.ru/moscow/firm/70000001057394703'],
    maxReviews: 100,
    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;
    }
}

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

$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;
}

Вакансии

$jobs = $client->scrapeJobs(
    location: 'Новосибирск',
    maxResults: 300,
    salaryMin: 80000,
);

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

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

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;
}

Требования

Лицензия

MIT

About

Типобезопасные DTO для 2gis через Apify

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages