From 32c58a2f76626cbb5cb0f9c33c18c4eae65a61c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 10 Sep 2024 11:23:36 +0900 Subject: [PATCH] Automation init...3 --- app/Controllers/Crawler/YamapController.php | 4 +++- app/Libraries/MyCrawler/MyCrawlerLibrary.php | 21 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/Controllers/Crawler/YamapController.php b/app/Controllers/Crawler/YamapController.php index 0820f41..5f93353 100644 --- a/app/Controllers/Crawler/YamapController.php +++ b/app/Controllers/Crawler/YamapController.php @@ -43,7 +43,9 @@ class YamapController extends CommonController //3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리 $fileEntitys = $crawler->detailPage($item["detail_url"]); //4.망보드 일반게시판에 게시물 등록 처리 - $crawler->createBoard($item, $fileEntitys); + if (count($fileEntitys)) { + $crawler->createBoard($item, $fileEntitys); + } $i++; log_message("notice", "게시물 {$i}번째 {$item["nickname"]} 작업완료."); } catch (\Exception $e) { diff --git a/app/Libraries/MyCrawler/MyCrawlerLibrary.php b/app/Libraries/MyCrawler/MyCrawlerLibrary.php index ae01f11..3e82b4e 100644 --- a/app/Libraries/MyCrawler/MyCrawlerLibrary.php +++ b/app/Libraries/MyCrawler/MyCrawlerLibrary.php @@ -37,23 +37,22 @@ abstract class MyCrawlerLibrary extends CommonLibrary //Download한 파일 저장후 추가작업시 사용 - protected function download_process($entity, int $file_sequence) - { - return $entity; - } - final protected function download(string $mediaType, Crawler $crawler, array $options, array $entitys = []): array { $nodes = $this->getNodes($crawler, $options); $file_sequence = 1; foreach ($nodes as $node) { - list($fileName, $content) = $this->getMySocket()->download($node->attr($options["attr"])); - $entity = $this->getMyStorage()->save($fileName, $mediaType, $content, $file_sequence); - if ($entity === null) { - continue; + try { + list($fileName, $content) = $this->getMySocket()->download($node->attr($options["attr"])); + $entity = $this->getMyStorage()->save($fileName, $mediaType, $content, $file_sequence); + if ($entity === null) { + continue; + } + $entitys[] = $entity; + $file_sequence++; + } catch (\Exception $e) { + log_message("notice", $e->getMessage()); } - $entitys[] = $this->download_process($entity, $file_sequence); - $file_sequence++; } return $entitys; }