Skip to content

Commit b70c4c6

Browse files
committed
init
0 parents  commit b70c4c6

24 files changed

Lines changed: 1794 additions & 0 deletions

‎.github/workflows/tests.yml‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php: ['8.3', '8.4']
17+
18+
name: PHP ${{ matrix.php }}
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
extensions: mbstring, json, curl
29+
coverage: none
30+
31+
- name: Install dependencies
32+
run: composer install --prefer-dist --no-interaction --no-progress
33+
34+
- name: Run tests
35+
run: composer test
36+
37+
code-style:
38+
runs-on: ubuntu-latest
39+
name: Code Style
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Setup PHP
46+
uses: shivammathur/setup-php@v2
47+
with:
48+
php-version: '8.3'
49+
extensions: mbstring
50+
coverage: none
51+
52+
- name: Install dependencies
53+
run: composer install --prefer-dist --no-interaction --no-progress
54+
55+
- name: Check code style
56+
run: composer cs -- -v
57+
58+
static-analysis:
59+
runs-on: ubuntu-latest
60+
name: Static Analysis
61+
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v4
65+
66+
- name: Setup PHP
67+
uses: shivammathur/setup-php@v2
68+
with:
69+
php-version: '8.3'
70+
extensions: mbstring
71+
coverage: none
72+
73+
- name: Install dependencies
74+
run: composer install --prefer-dist --no-interaction --no-progress
75+
76+
- name: Run PHPStan
77+
run: composer analyse

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
.phpstan.cache/
3+
composer.lock
4+
.phpunit.result.cache

‎README.md‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Yandex Parser PHP
2+
3+
PHP-библиотека для парсинга данных Яндекса: организации и места (Яндекс Карты), отзывы (Яндекс Карты), товары (Яндекс Маркет).
4+
5+
Работает через [Apify API](https://apify.com/) — запускает акторы и возвращает типизированные DTO.
6+
7+
## Установка
8+
9+
```bash
10+
composer require scraper-apis/yandex-parser
11+
```
12+
13+
## Быстрый старт
14+
15+
```php
16+
use YandexParser\Client;
17+
18+
$client = new Client('apify_api_ваш_токен');
19+
20+
// Поиск ресторанов в Москве
21+
$places = $client->scrapePlaces(
22+
query: ['ресторан'],
23+
location: 'Москва',
24+
maxResults: 50,
25+
);
26+
27+
foreach ($places as $place) {
28+
echo "{$place->title} — {$place->address}" . PHP_EOL;
29+
echo "Рейтинг: {$place->rating}, отзывов: {$place->reviewCount}" . PHP_EOL;
30+
31+
if ($place->hasContactInfo()) {
32+
echo "Тел: {$place->getFirstPhone()}" . PHP_EOL;
33+
}
34+
}
35+
```
36+
37+
## Методы
38+
39+
### Организации (Яндекс Карты)
40+
41+
```php
42+
use YandexParser\Language;
43+
44+
$places = $client->scrapePlaces(
45+
query: ['стоматология', 'клиника'],
46+
location: 'Санкт-Петербург',
47+
maxResults: 200,
48+
language: Language::Russian,
49+
options: [
50+
'filterRating' => 4.5,
51+
'filterOpenNow' => true,
52+
'filterCardPayment' => true,
53+
'maxPhotos' => 5,
54+
],
55+
);
56+
```
57+
58+
### Отзывы (Яндекс Карты)
59+
60+
```php
61+
use YandexParser\ReviewSort;
62+
63+
$reviews = $client->scrapeReviews(
64+
startUrls: ['https://yandex.ru/maps/org/pushkin/1124715036/'],
65+
maxReviewsPerPlace: 100,
66+
reviewSort: ReviewSort::Newest,
67+
minRating: 1,
68+
maxRating: 3,
69+
);
70+
71+
foreach ($reviews as $review) {
72+
echo "{$review->authorName}: {$review->rating}/5" . PHP_EOL;
73+
74+
if ($review->hasBusinessReply()) {
75+
echo "Ответ: {$review->getBusinessReplyText()}" . PHP_EOL;
76+
}
77+
}
78+
```
79+
80+
### Товары (Яндекс Маркет)
81+
82+
```php
83+
use YandexParser\MarketSort;
84+
use YandexParser\MarketRegion;
85+
86+
$products = $client->scrapeProducts(
87+
query: 'ноутбук ASUS',
88+
maxItems: 50,
89+
region: MarketRegion::Moscow,
90+
sort: MarketSort::PriceAsc,
91+
options: [
92+
'priceFrom' => 30000,
93+
'priceTo' => 80000,
94+
],
95+
);
96+
97+
foreach ($products as $product) {
98+
echo "{$product->title} — {$product->getPriceFormatted()}" . PHP_EOL;
99+
echo "Продавец: {$product->sellerName}, рейтинг: {$product->rating}" . PHP_EOL;
100+
101+
$discount = $product->getYaBankDiscount();
102+
if ($discount !== null) {
103+
echo "Скидка по Я.Банку: {$discount}%" . PHP_EOL;
104+
}
105+
}
106+
```
107+
108+
## Перечисления
109+
110+
| Enum | Значения |
111+
|------|----------|
112+
| `Language` | `Auto`, `Russian`, `English`, `Turkish`, `Ukrainian`, `Kazakh` |
113+
| `ReviewSort` | `Relevance`, `Newest`, `Highest`, `Lowest` |
114+
| `MarketSort` | `Default`, `Popular`, `PriceAsc`, `PriceDesc`, `Rating` |
115+
| `MarketRegion` | `Moscow`, `SaintPetersburg`, `Yekaterinburg`, `Kazan`, `Novosibirsk`, `NizhnyNovgorod`, `Samara`, `RostovOnDon`, `Krasnodar`, `Chelyabinsk`, `Ufa`, `Perm`, `Voronezh`, `Volgograd`, `Krasnoyarsk`, `Omsk` |
116+
117+
## Конфигурация
118+
119+
```php
120+
use YandexParser\Client;
121+
use YandexParser\Config;
122+
123+
// Изменить таймаут или базовый URL
124+
$client = new Client('токен', new Config(
125+
apiToken: 'токен',
126+
timeout: 600,
127+
));
128+
```
129+
130+
## Обработка ошибок
131+
132+
```php
133+
use YandexParser\Exception\ApiException;
134+
use YandexParser\Exception\RateLimitException;
135+
136+
try {
137+
$places = $client->scrapePlaces(query: ['кафе'], location: 'Казань');
138+
} catch (RateLimitException $e) {
139+
sleep($e->retryAfter);
140+
// повторить запрос
141+
} catch (ApiException $e) {
142+
echo "Ошибка API: {$e->getMessage()}" . PHP_EOL;
143+
}
144+
```
145+
146+
## Требования
147+
148+
- PHP 8.3+
149+
- Токен [Apify API](https://console.apify.com/account/integrations)
150+
151+
## Лицензия
152+
153+
MIT

‎composer.json‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "scraper-apis/yandex-parser",
3+
"description": "PHP client library for scraping Yandex data (places, reviews, market products) using Apify actors",
4+
"type": "library",
5+
"license": "MIT",
6+
"require": {
7+
"php": "^8.3",
8+
"guzzlehttp/guzzle": "^7.0"
9+
},
10+
"require-dev": {
11+
"pestphp/pest": "^4.0",
12+
"laravel/pint": "^1.0",
13+
"phpstan/phpstan": "^1.0"
14+
},
15+
"autoload": {
16+
"psr-4": {
17+
"YandexParser\\": "src/"
18+
}
19+
},
20+
"autoload-dev": {
21+
"psr-4": {
22+
"YandexParser\\Tests\\": "tests/"
23+
}
24+
},
25+
"scripts": {
26+
"test": "pest",
27+
"cs": "pint --test",
28+
"cs:fix": "pint",
29+
"analyse": "phpstan analyse"
30+
},
31+
"config": {
32+
"sort-packages": true,
33+
"allow-plugins": {
34+
"pestphp/pest-plugin": true
35+
}
36+
}
37+
}

‎phpstan.neon‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
tmpDir: .phpstan.cache

‎phpunit.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true">
6+
<testsuites>
7+
<testsuite name="Tests">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
<source>
12+
<include>
13+
<directory>src</directory>
14+
</include>
15+
</source>
16+
</phpunit>

‎pint.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "laravel"
3+
}

0 commit comments

Comments
 (0)