adding new method to PageScrapper, adding new page

This commit is contained in:
Holiienko Roman 2024-01-24 13:30:27 +03:00
parent f8155f2557
commit 05fbca2353
7 changed files with 47 additions and 25 deletions

View File

@ -29,15 +29,27 @@ class PageScrapper
public function normalizeURLFile($content) public function normalizeURLFile($content)
{ {
//$content = preg_replace('/<a href="(.*)"/isU', 'https://mkgtu.ru' ,$content );
$rez = preg_match_all('/<a href="(.*)">/isU',$content,$arr);
foreach ($arr[1] as $el) {
if (!str_contains($el, 'https://')){
$content = str_replace($el,'https://mkgtu.ru' . $el,$content);
$rez = preg_match_all('/<a href="(.*)">/isU',$content,$arr);
$arr[1] = array_unique($arr[1]);
foreach ($arr[1] as $el) {
if (!str_starts_with($el, 'https')){
$content = str_replace($el,'https://mkgtu.ru' . $el,$content);
} }
} }
return $content; return $content;
}
public function cutHTML($content,$strForScissors)
{
$arr = [];
$rez = preg_match_all($strForScissors, $content, $arr);
$content = str_replace($arr[1],'',$content);
return $content;
} }
} }

View File

@ -49,7 +49,7 @@
</div> </div>
<div class="col-8"> <div class="col-8">
<a href="postup-col.php"> <a href="{{ route('kolledzh') }}">
<h4> <h4>
<div <div
class="d-flex justify-content-start align-items-center w-100 h-100 border border-secondary m-1 p-4 buttonHover rounded-2"> class="d-flex justify-content-start align-items-center w-100 h-100 border border-secondary m-1 p-4 buttonHover rounded-2">

View File

@ -0,0 +1,19 @@
@extends('layouts.applicant-layout')
@section('content')
<div class=" fw-bolder fs-1 text-center py-5 lh-lg"> Для поступающих на обучение по программам среднего профессионального образования </div>
<div class="container pt-4 d-flex justify-content-center">
<div class="col-10">
@php
use App\Services\PageScrapper;
$pageScrapper = new PageScrapper("https://mkgtu.ru/postuplenie/priemnaya-kampaniya/kolledzh/", '<div class=["\']content_info["\']>');
$row = $pageScrapper->getHTML();
$content = $pageScrapper->normalizeURLFile($row);
$content = $pageScrapper->cutHTML($content,'/<footer(.*)<\/footer>/isU');
echo $content;
@endphp
</div>
</div>
@endsection

View File

@ -1,6 +1,6 @@
@extends('layouts.applicant-layout') @extends('layouts.applicant-layout')
@section('content') @section('content')
<div class=" fw-bolder fs-1 text-center py-5"> Для поступающих на программы бакалавриата, магистратуры </div> <div class=" fw-bolder fs-1 text-center py-5 lh-lg"> Для поступающих на программы бакалавриата, магистратуры </div>
<div class="container pt-4 d-flex justify-content-center"> <div class="container pt-4 d-flex justify-content-center">
<div class="col-10"> <div class="col-10">
@ -9,14 +9,7 @@
$pageScrapper = new PageScrapper("https://mkgtu.ru/postuplenie/priemnaya-kampaniya/spetsialitet-magistratura-2022/", '<div class=["\']content_info["\']>'); $pageScrapper = new PageScrapper("https://mkgtu.ru/postuplenie/priemnaya-kampaniya/spetsialitet-magistratura-2022/", '<div class=["\']content_info["\']>');
$row = $pageScrapper->getHTML(); $row = $pageScrapper->getHTML();
$content = $pageScrapper->normalizeURLFile($row); $content = $pageScrapper->normalizeURLFile($row);
$content = $pageScrapper->cutHTML($content,'/<footer(.*)<\/footer>/isU');
$page = "https://mkgtu.ru/postuplenie/priemnaya-kampaniya/spetsialitet-magistratura-2022/";
$strForScissors = '/<footer(.*)<\/footer>/isU';
$tmp = preg_match_all($strForScissors, $content, $arr);
$content = str_replace($arr[1],'',$content);
echo $content ; echo $content ;
@endphp @endphp

View File

@ -1,6 +1,6 @@
@extends('layouts.applicant-layout') @extends('layouts.applicant-layout')
@section('content') @section('content')
<div class=" fw-bolder fs-1 text-center py-5"> Веб-консультации для абитуриентов и их родителей </div> <div class=" fw-bolder fs-1 text-center py-5 lh-lg"> Веб-консультации для абитуриентов и их родителей </div>
<div class="container pt-4 d-flex justify-content-center"> <div class="container pt-4 d-flex justify-content-center">
<div class="col-10"> <div class="col-10">
@ -9,10 +9,7 @@
$pageScrapper = new PageScrapper("https://www.mkgtu.ru/postuplenie/web-consultations/", '<div class=["\']content_info["\']>'); $pageScrapper = new PageScrapper("https://www.mkgtu.ru/postuplenie/web-consultations/", '<div class=["\']content_info["\']>');
$row = $pageScrapper->getHTML(); $row = $pageScrapper->getHTML();
$content = $pageScrapper->normalizeURLFile($row); $content = $pageScrapper->normalizeURLFile($row);
$page = "https://mkgtu.ru/postuplenie/priemnaya-kampaniya/spetsialitet-magistratura-2022/"; $content = $pageScrapper->cutHTML($content,'/<footer(.*)<\/footer>/isU');
$strForScissors = '/<footer(.*)<\/footer>/isU';
$tmp = preg_match_all($strForScissors, $content, $arr);
$content = str_replace($arr[1],'',$content);
echo $content; echo $content;
@endphp @endphp

View File

@ -30,7 +30,7 @@
} }
</style> </style>
<div class=" fw-bolder fs-1 text-center py-5"> Подача документов онлайн </div> <div class=" fw-bolder fs-1 text-center py-5 lh-lg"> Подача документов онлайн </div>
<div class="container pt-4 d-flex justify-content-center"> <div class="container pt-4 d-flex justify-content-center">
<div class="col-10"> <div class="col-10">
@ -39,10 +39,7 @@
$pageScrapper = new PageScrapper("https://mkgtu.ru/postuplenie/podat-dokumenty-onlayn/", '<div class=["\']content_info["\']>'); $pageScrapper = new PageScrapper("https://mkgtu.ru/postuplenie/podat-dokumenty-onlayn/", '<div class=["\']content_info["\']>');
$row = $pageScrapper->getHTML(); $row = $pageScrapper->getHTML();
$content = $pageScrapper->normalizeURLFile($row); $content = $pageScrapper->normalizeURLFile($row);
$page = "https://mkgtu.ru/postuplenie/priemnaya-kampaniya/spetsialitet-magistratura-2022/"; $content = $pageScrapper->cutHTML($content,'/<footer(.*)<\/footer>/isU');
$strForScissors = '/<footer(.*)<\/footer>/isU';
$tmp = preg_match_all($strForScissors, $content, $arr);
$content = str_replace($arr[1],'',$content);
echo $content; echo $content;
@endphp @endphp

View File

@ -42,6 +42,10 @@ Route::get('/spetsialitet-magistratura', function () {
return view('menu.abitur.spetsialitet-magistratura'); return view('menu.abitur.spetsialitet-magistratura');
})->name('spetsialitet-magistratura'); })->name('spetsialitet-magistratura');
Route::get('/kolledzh', function () {
return view('menu.abitur.kolledzh');
})->name('kolledzh');
Route::post('/uploadfile', [UploadFileController::class, 'showUploadFile'])->name('uploadfile'); Route::post('/uploadfile', [UploadFileController::class, 'showUploadFile'])->name('uploadfile');
Route::get('/dashboard', function () { Route::get('/dashboard', function () {