Работает обработка ссылок на таблицы с численностью

This commit is contained in:
2024-09-06 14:11:38 +03:00
parent 04374fef40
commit 2be45826c1
1698 changed files with 138656 additions and 174 deletions

View File

@ -1,10 +1,14 @@
<?php
/**
* Парсер информации об образовательной организации
* с её сайта с использованием микроразметки
*/
namespace ContingentParser\Parser;
use DOMDocument;
use DOMXPath;
class ContingentParser
final class ContingentParser
{
private ?DOMXPath $xpath;
private DOMDocument $dom;
@ -33,7 +37,7 @@ class ContingentParser
}
}
private function setEncoding(string &$html) : void
private function setEncoding(string &$html): void
{
$encoding = mb_detect_encoding($html, 'UTF-8, windows-1251');
if ($encoding != self::ENCODING) {
@ -46,7 +50,7 @@ class ContingentParser
}
$html = mb_convert_encoding($html,'HTML-ENTITIES','UTF-8');
}
public function getDataTable() : array
public function getDataTable(): array
{
if (empty($this->xpath)) return [];
@ -77,7 +81,7 @@ class ContingentParser
return $records;
}
private function parseContingent() : array
private function parseContingent(): array
{
$data = [];
foreach (self::FIELDS as $field => $tag) {
@ -100,8 +104,15 @@ class ContingentParser
public function getLink(): string
{
$needle = "Информация о численности обучающихся";
$data = $this->dom->getElementsByTagName('a');
var_dump($data->item(0)->getAttribute('href'));
for ($i = 0; $i < $data->length; $i++) {
$haystack = $data->item($i)->textContent;
$isInformationOfContingent = strpos($haystack, $needle) !== false;
if ($isInformationOfContingent) {
return $data->item($i)->getAttribute('href');
}
}
return '';
}
}