diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bd132c7..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.log -.yaml diff --git a/app/app.php b/app/app.php index 4947e22..f3a14aa 100644 --- a/app/app.php +++ b/app/app.php @@ -64,12 +64,12 @@ for ($i = $start; $i < count($sites); $i++) { $client = new Client([ 'allow_directs' => true, 'track_redirects' => true, + 'connect_timeout' => 300.0, 'verify' => false, // 'http_errors' => false, 'headers' => [ 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 YaBrowser/24.6.0.0 Safari/537.36', - 'Content-Type' => 'text/html;charset=utf-8', - 'timeout' => 300 + 'Content-Type' => 'text/html;charset=utf-8' ] ]); @@ -109,17 +109,12 @@ for ($i = $start; $i < count($sites); $i++) { } unset($contingent); } - } catch (ClientException $e) { + } catch (ClientException + | RequestException + | ConnectException + | ServerException $e + ) { $message = implode(' ', $sites[$i]) . "\t" . $e->getCode() . "\t" . $e->getMessage(); Logger::log($pathLogErrorHttp, $message); - } catch (RequestException $e) { - $message = implode(' ', $sites[$i]) . "\t" . $e->getCode() . "\t" . $e->getMessage(); - Logger::log($pathLogErrorHttp, $message); - } catch (ConnectException $e) { - $message = implode(' ', $sites[$i]) . "\t" . $e->getCode() . "\t" . $e->getMessage(); - Logger::log($pathLogErrorHttp, $message); - } catch (ServerException $e) { - $message = implode(' ', $sites[$i]) . "\t" . $e->getCode() . "\t" . $e->getMessage(); - Logger::log($pathLogErrorHttp, $message); - } + } } diff --git a/app/library/ContingentParser.php b/app/library/ContingentParser.php index 90ce0b2..b14f92d 100644 --- a/app/library/ContingentParser.php +++ b/app/library/ContingentParser.php @@ -26,8 +26,16 @@ class ContingentParser public function __construct(string $html, string $template) { libxml_use_internal_errors(true); - $dom = new \DOMDocument(); - $dom->loadHTML(mb_convert_encoding($html,'HTML-ENTITIES','UTF-8')); + $dom = new \DOMDocument( + encoding: "UTF-8" + ); + $html = mb_convert_encoding( + $html, + 'UTF-8', + mb_detect_encoding($html, 'UTF-8, windows-1251') + ); + $html = str_replace('windows-1251','utf-8', $html); + $dom->loadHTML($html); $this->xpath = new \DOMXPath($dom); $this->template = $template; } @@ -52,7 +60,8 @@ class ContingentParser { $data = $this->parse(); $records = array(); - + // var_dump($data); + // exit(0); if ($data == null) return []; $equal = $data['eduName']->length; diff --git a/app/library/Database.php b/app/library/Database.php index 2782601..3972838 100644 --- a/app/library/Database.php +++ b/app/library/Database.php @@ -69,7 +69,7 @@ class Database Logger::log(self::$logFile, "Запрос выполнен успешно!"); } catch (PDOException $e) { // При ошибке запроса сохраняем валидные данные в yaml-файл - $yaml = Yaml::dump($params); + $yaml = Yaml::dump([$params]); file_put_contents(__DIR__ . '/not-recorded-in-db.yaml', $yaml, FILE_APPEND); $message = "Ошибка запроса:" . $e->getMessage(); Logger::log(self::$logFile, $message); diff --git a/script.php b/script.php index 5228ec4..629e0e2 100644 --- a/script.php +++ b/script.php @@ -31,6 +31,6 @@ if(array_depth($data) == 2){ ContingentManager::getInstance()->insertContingent($db, $data); } else { foreach ($data as $value) { - // ContingentManager::getInstance()->insertContingent($db, $value); + ContingentManager::getInstance()->insertContingent($db, $value); } }