From 8b3c16ccaff159d93b56bc7391a555661e445ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 3 Sep 2024 19:45:22 +0900 Subject: [PATCH] Automationn init... --- app/Controllers/CLI/Crawler.php | 8 ++++++-- app/Libraries/YamapLibrary.php | 17 ++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/Controllers/CLI/Crawler.php b/app/Controllers/CLI/Crawler.php index a1d7adf..8c12b54 100644 --- a/app/Controllers/CLI/Crawler.php +++ b/app/Controllers/CLI/Crawler.php @@ -7,7 +7,7 @@ use App\Libraries\YamapLibrary; class Crawler extends BaseController { - public function yamap(...$params) + public function yamap(...$params): bool { try { $isDebug = in_array("debug", $params); @@ -15,7 +15,11 @@ class Crawler extends BaseController $library->setDebug($isDebug); //1. MainPage $url = getenv("yamap.url.main"); - $links = $library->getLinksByMainPage($url); + $crawler = $library->getCrawlerByMainPage($url); + $links = $library->getLinks($crawler,); + if (!count($links)) { + throw new \Exception("Target Links가 없습니다."); + } //2. TargetPage : div.contents 가진 객체를 찾아서 첫번쨰 요소에서만 참조 $url = !in_array("debug", $params) ? getenv("yamap.url.test") : $links[0]["href"]; $crawler = $library->getCrawlerByDetailPage($url); diff --git a/app/Libraries/YamapLibrary.php b/app/Libraries/YamapLibrary.php index e254ece..a9dd3b1 100644 --- a/app/Libraries/YamapLibrary.php +++ b/app/Libraries/YamapLibrary.php @@ -20,7 +20,7 @@ class YamapLibrary $this->_host = $host; } - public function getMyWeb() + public function getMyWeb(): MyWebLibrary { if ($this->_web === null) { $this->_web = new MyWebLibrary($this->getHost()); @@ -28,7 +28,7 @@ class YamapLibrary } return $this->_web; } - public function getMyStorage() + public function getMyStorage(): MyStorageLibrary { if ($this->_storage === null) { $this->_storage = new MyStorageLibrary(); @@ -36,7 +36,7 @@ class YamapLibrary } return $this->_storage; } - public function getMyCrawler() + public function getMyCrawler(): MyCrawlerLibrary { if ($this->_crawler === null) { $this->_crawler = new MyCrawlerLibrary(); @@ -96,7 +96,7 @@ class YamapLibrary } // 파일 다운로드 메서드 - final public function download($url) + final public function download($url): bool { try { $fileNames = explode('/', $url); @@ -130,15 +130,10 @@ class YamapLibrary } } - public function getLinksByMainPage(string $url): array + public function getCrawlerByMainPage(string $url): Crawler { $html = $this->getMyWeb()->getContent($url);; - $crawler = $this->getMyCrawler()->createCrawler($html)->filter("div.bbs_list")->first();; - $links = $this->getLinks($crawler,); - if (!count($links)) { - throw new \Exception("Target Links가 없습니다."); - } - return $links; + return $this->getMyCrawler()->createCrawler($html)->filter("div.bbs_list")->first(); } public function getCrawlerByDetailPage(string $url): Crawler {