Automation/app/Controllers/CLI/Crawler.php
2024-09-03 19:25:54 +09:00

34 lines
1.1 KiB
PHP

<?php
namespace App\Controllers\CLI;
use App\Controllers\BaseController;
use App\Libraries\YamapLibrary;
class Crawler extends BaseController
{
public function yamap(...$params)
{
try {
$isDebug = in_array("debug", $params);
$library = new YamapLibrary(getenv("crawler.yamap.host"));
$library->setDebug($isDebug);
//1. MainPage
$url = getenv("crawler.yamap.url.main");
$links = $library->getLinksByMainPage($url);
//2. TargetPage : div.contents 가진 객체를 찾아서 첫번쨰 요소에서만 참조
$url = !in_array("debug", $params) ? getenv("crawler.yamap.url.target") : $links[0]["href"];
$crawler = $library->getCrawlerByDetailPage($url);
//3. Image
$library->getImages($crawler);
//4. Video
$library->getVideos($crawler);
log_message("info", "완료되었습니다.");
return true;
} catch (\Exception $e) {
log_message("error", $e->getMessage());
return false;
}
}
}