Merge remote-tracking branch 'origin/main'

# Conflicts:
#	app/Services/PageScrapper.php
This commit is contained in:
aslan 2024-01-31 15:45:38 +03:00
commit 06b662d39a
1 changed files with 36 additions and 22 deletions

View File

@ -93,31 +93,45 @@ class PageScrapper
$links = $content->find('a[href]');
$srclinks = $content->find('img[src]');
// $html0 = $this->document->format()->html();
// dd($html0);
// $html0 = $content->find('a[href]')->set;
// foreach ($links as $k => $link) {
// $href = $link->attr('href');
//
// if (!str_contains($link->attr('href'), "https://")) {
//
//
// $tmp = explode('/', rawurldecode($href));
// foreach ( $tmp as $k => $v) {
// $tmp[$k] = rawurlencode($v);
// }
// $href = implode('/', $tmp);
// $newHref = 'https://mkgtu.ru' . $href;
// echo 'https://mkgtu.ru' . $href;
// echo '<br>';
// echo '<br>';
// $html0 = str_replace($href, $newHref, $html0);
// }
// }
$html0 = $content->html();
preg_match_all('/<a href="(.*)">/isU', $html0, $arr);
foreach ($arr[1] as $el) {
$html0 = str_replace($el, urldecode($el), $html0);
}
preg_match_all('/<img src="(.*)">/isU', $html0, $arr2);
foreach ($arr2[1] as $el) {
$html0 = str_replace($el, urldecode($el), $html0);
}
foreach ($links as $k => $link) {
$href = $link->attr('href');
if (!str_contains($link->attr('href'), "https://")) {
$unchanged = $link->attr('href');
$changed = $link->href = 'https://mkgtu.ru' . $href;
$html0 = str_replace(urldecode($unchanged), $changed, $html0);
}
}
foreach ($srclinks as $k => $srclink) {
$src = $srclink->attr('src');
if (!str_contains($srclink->attr('src'), "https://")) {
$unchanged = $srclink->attr('src');
$changed = $srclink->src = 'https://mkgtu.ru' . $src;
$html0 = str_replace(urldecode($unchanged), $changed, $html0);
}
}
// foreach ($srclinks as $k => $srclink) {
// $src = $srclink->attr('src');
//
// if (!str_contains($srclink->attr('src'), "https://")) {
//
//
// $tmp = explode('/', rawurldecode($src));
// foreach ( $tmp as $k => $v) {
// $tmp[$k] = rawurlencode($v);