144 lines
4.0 KiB
PHP
Executable File
144 lines
4.0 KiB
PHP
Executable File
<?php
|
|
require 'vendor/autoload.php';
|
|
require_once 'Specialization.php';
|
|
// require_once 'Size.php';
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
const TEMPLATE = '//tr[@itemprop="eduChislen"]//';
|
|
|
|
$dbconfig = [
|
|
'host' => '10.90.1.201',
|
|
'database' => 'opendata',
|
|
'user' => 'niimko_user',
|
|
'password' => 'MOhA17FeboXE'
|
|
];
|
|
|
|
$fields = [
|
|
'eduCode' => 'td',
|
|
'eduName' => 'td',
|
|
'eduLevel' => 'td',
|
|
'eduForm' => 'td',
|
|
// 'numberBF' => 'th',
|
|
// 'numberBFF' => 'th',
|
|
// 'numberBR' => 'th',
|
|
// 'numberBRF' => 'th',
|
|
// 'numberBM' => 'th',
|
|
// 'numberBMF' => 'th',
|
|
// 'numberP' => 'th',
|
|
// 'numberPF' => 'th',
|
|
'numberAll' => 'th',
|
|
];
|
|
$data = [];
|
|
|
|
$client = new Client();
|
|
$response = $client->get('https://marsu.ru/sveden/education/eduChislen.php');
|
|
$html = $response->getBody()->getContents();
|
|
libxml_use_internal_errors(true);
|
|
|
|
$dom = new DOMDocument();
|
|
$dom->loadHTML($html);
|
|
$xpath = new DOMXPath($dom);
|
|
|
|
foreach ($fields as $field => $tag) {
|
|
$data[$field] = $xpath->query(TEMPLATE . $tag . "[@itemprop=\"$field\"]");
|
|
}
|
|
|
|
// echo "<pre>";
|
|
// print_r($data['numberAll'][0]);
|
|
// echo "</pre>";
|
|
|
|
$specialization = new Specialization();
|
|
// $sizeFederalBudget = new Size();
|
|
// $sizeRussianBudget = new Size();
|
|
// $sizeLocalBudget = new Size();
|
|
// $sizeIndividualsOrLegalEntitiesBudget = new Size();
|
|
$records = [];
|
|
$size = [];
|
|
|
|
for ($i = 0; $i < $data['numberAll']->length; $i++) {
|
|
// $sizeFederalBudget->update(
|
|
// $data['numberBF']->item($i)->textContent,
|
|
// $data['numberBFF']->item($i)->textContent
|
|
// );
|
|
// $size['бюджетных ассигнований федерального бюджета'] = $sizeFederalBudget->getData();
|
|
|
|
// $sizeRussianBudget->update(
|
|
// $data['numberBR']->item($i)->textContent,
|
|
// $data['numberBRF']->item($i)->textContent
|
|
// );
|
|
// $size['бюджетов субъектов Российской Федерации'] = $sizeRussianBudget->getData();
|
|
|
|
// $sizeLocalBudget->update(
|
|
// $data['numberBM']->item($i)->textContent,
|
|
// $data['numberBMF']->item($i)->textContent
|
|
// );
|
|
// $size['местных бюджетов'] = $sizeLocalBudget->getData();
|
|
|
|
// $sizeIndividualsOrLegalEntitiesBudget->update(
|
|
// $data['numberP']->item($i)->textContent,
|
|
// $data['numberPF']->item($i)->textContent
|
|
// );
|
|
// $size['средств физических и (или) юридических лиц'] = $sizeIndividualsOrLegalEntitiesBudget->getData();
|
|
|
|
$specialization->update(
|
|
$data['eduCode']->item($i)->textContent,
|
|
$data['eduName']->item($i)->textContent,
|
|
$data['eduLevel']->item($i)->textContent,
|
|
$data['eduForm']->item($i)->textContent,
|
|
// [],
|
|
(int)$data['numberAll']->item($i)->textContent
|
|
);
|
|
$records[] = $specialization->getData();
|
|
$size = [];
|
|
}
|
|
|
|
// echo "<pre>";
|
|
// print_r($records[0]);
|
|
// echo "</pre>";
|
|
|
|
try {
|
|
$pdo = new PDO(
|
|
"mysql:host={$dbconfig['host']};dbname={$dbconfig['database']}",
|
|
$dbconfig['user'],
|
|
$dbconfig['password']
|
|
);
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
echo "Подключение успешно!";
|
|
} catch (PDOException $e) {
|
|
echo "Ошибка подключения: " . $e->getMessage() . "\n";
|
|
}
|
|
|
|
$sql = "
|
|
INSERT
|
|
INTO sveden_education_contingent (
|
|
spec_code,
|
|
spec_name,
|
|
edu_level,
|
|
edu_forms,
|
|
contingent
|
|
) VALUES (
|
|
:spec_code,
|
|
:spec_name,
|
|
:edu_level,
|
|
:edu_forms,
|
|
:contingent
|
|
)
|
|
";
|
|
|
|
// Почему-то не сработала
|
|
// foreach ($records as $record) {
|
|
// $sth = $pdo->prepare($sql);
|
|
// try {
|
|
// $sth->execute($record);
|
|
// } catch (PDOException $e) {
|
|
// echo "Ошибка выполнения запроса:". $e->getMessage() . "";
|
|
// }
|
|
// }
|
|
|
|
$sql = 'SELECT * FROM sveden_education_contingent';
|
|
$array = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
|
|
|
|
echo "<pre>";
|
|
print_r($array);
|
|
echo "</pre>";
|