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

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,6 +1,7 @@
<?php
namespace ContingentParser\Http;
use ContingentParser\Color;
use ContingentParser\Printer;
use GuzzleHttp\Client;
use GuzzleHttp\TransferStats;
@ -17,10 +18,11 @@ final class HttpClientFacade
* @param array $site Идентификатор организации, и базовый URL
* @return string
*/
public function processEducationContingentSites(
public function getContentOfSite(
string $url,
array $site
) : string {
array $site,
string $uri = "sveden/education/"
): string {
try {
$client = $this->createClient($url);
// Запрос по базовому uri
@ -30,18 +32,18 @@ final class HttpClientFacade
}
]);
Printer::println("Redirect $url -> $redirectUrl");
$url .= substr($url, -1) == '/' ? '':'/';
$url .= "sveden/education/study";
$url .= substr($url, -1) == '/' ? '' : '/';
$url .= substr($uri, 0, 1) == '/' ? substr($uri, 1) : $uri;
Printer::println("Parsing for $url");
$response = $client->get($url);
$httpCode = $response->getStatusCode();
Printer::println("HTTP-code: $httpCode", 'blue');
Printer::println("HTTP-code: $httpCode", Color::BLUE);
$html = $response->getBody()->getContents();
} catch (\Exception $e
) {
Printer::println("HTTP-code: ".$e->getCode(), 'red');
Printer::println("HTTP-code: ".$e->getCode(), Color::RED);
$html = $this->handleException($url, $site);
} finally {
return $html;
@ -75,7 +77,7 @@ final class HttpClientFacade
* Конфигурация клиента
* @return array
*/
private function config() : array
private function config(): array
{
return [
'force_ip_resolve' => 'v4',
@ -87,7 +89,7 @@ final class HttpClientFacade
'protocols' => ['http', 'https'],
'track_redirects' => true
],
'connect_timeout' => 300.0,
'connect_timeout' => 90.0,
'verify' => false,
'headers' => [
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) '