Skip to content

Instantly share code, notes, and snippets.

@olegopro
Created January 16, 2025 16:19
Show Gist options
  • Save olegopro/ba3313d11ea62da1a6b46113a80a287b to your computer and use it in GitHub Desktop.
Save olegopro/ba3313d11ea62da1a6b46113a80a287b to your computer and use it in GitHub Desktop.
Извлечение уникальных доменов из файла .har с помощью PHP
<?php
// Путь к вашему файлу .har
$filePath = '/Users/evilgazz/Desktop/chat.mistral.ai.har';
// Загрузите содержимое файла .har
$harContent = file_get_contents($filePath);
// Декодируйте JSON
$harData = json_decode($harContent, true);
// Регулярное выражение для извлечения доменов
$domainPattern = '/https?:\/\/([^\/"]+)/';
// Извлечение всех URL
$urls = array_column($harData['log']['entries'], 'request', 'url');
// Извлечение доменов
$domains = [];
foreach ($harData['log']['entries'] as $entry) {
$url = $entry['request']['url'];
if (preg_match($domainPattern, $url, $matches)) {
$domains[] = $matches[1];
}
}
// Удаление дубликатов
$uniqueDomains = array_unique($domains);
// Вывод доменов
foreach ($uniqueDomains as $domain) {
echo $domain . PHP_EOL;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment