feat(автоподбор шаг2): справочники 2ГИС через xfetch.ru
Антибот 2ГИС бьём сервисом xfetch.ru (render:true, timeout:20 — без timeout страница не дорисовывается). Доказано на живом КрасЛомбаре: поиск → 12 филиалов → телефон + адрес каждой карточки. - PageFetcher — граница «достать HTML» (тестируется без сети) - XfetchClient — POST к xfetch, декод base64; без ключа молча пусто - XfetchDirectoryFetcher — список→филиалы→карточки через DirectoryParser - DirectoryParser — чтение списка и карточки 2ГИС (был в хвостах) - config services.xfetch + .env.example; ключ только в .env (gitignored) Яндекс.Карты — отдельно (другой формат URL карточек). TDD: Autopodbor 46/46. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Services\Autopodbor\Agent\Fetch\XfetchClient;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
it('декодирует HTML из base64-ответа xfetch', function () {
|
||||
Http::fake([
|
||||
'xf4.ru/*' => Http::response([
|
||||
'status_code' => 200,
|
||||
'response_body_base64' => base64_encode('<html>привет</html>'),
|
||||
]),
|
||||
]);
|
||||
$client = new XfetchClient('test-key');
|
||||
expect($client->html('https://2gis.ru/x'))->toBe('<html>привет</html>');
|
||||
});
|
||||
|
||||
it('без ключа не ходит в сеть и возвращает пусто', function () {
|
||||
Http::fake();
|
||||
$client = new XfetchClient(null);
|
||||
expect($client->html('https://2gis.ru/x'))->toBe('');
|
||||
Http::assertNothingSent();
|
||||
});
|
||||
|
||||
it('шлёт url, api_key и render:true на endpoint xfetch', function () {
|
||||
Http::fake(['xf4.ru/*' => Http::response(['response_body_base64' => base64_encode('ok')])]);
|
||||
(new XfetchClient('k123'))->html('https://2gis.ru/y');
|
||||
Http::assertSent(fn ($r) => $r->url() === 'https://xf4.ru/fetch'
|
||||
&& $r['url'] === 'https://2gis.ru/y'
|
||||
&& $r['api_key'] === 'k123'
|
||||
&& $r['render'] === true);
|
||||
});
|
||||
Reference in New Issue
Block a user