93 lines
4.7 KiB
PHP
93 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Libraries\MyCrawler;
|
|
|
|
use App\Libraries\MySocket\WebSocket;
|
|
use App\Libraries\MyStorage\MangboardStorage;
|
|
use App\Entities\Mangboard\UserEntity;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
class YamoonCrawler extends MyCrawler
|
|
{
|
|
private $_category = "";
|
|
private $_user_entity = null;
|
|
private $_myStorage = null;
|
|
public function __construct(string $host, string $category, UserEntity $user_entity)
|
|
{
|
|
parent::__construct(new WebSocket($host));
|
|
$this->_category = $category;
|
|
$this->_user_entity = $user_entity;
|
|
}
|
|
final protected function getMyStorage()
|
|
{
|
|
if ($this->_myStorage === null) {
|
|
$this->_myStorage = new MangboardStorage($this->_category, $this->_user_entity);
|
|
}
|
|
return $this->_myStorage;
|
|
}
|
|
protected function detail_page(array $listInfo): array
|
|
{
|
|
$response = $this->getMySocket()->getContent("/newboard/yamoonboard/" . $listInfo['detail_url']);
|
|
//작성시간
|
|
// $selector = $this->getSelector($response, getenv("yamoon.view.regdate.tag"));
|
|
// $listInfo['date'] = trim($selector->text());
|
|
//작성내용
|
|
$tag = getenv("yamoon.view.content.tag");
|
|
return $this->getMediaUrls($response, $tag, $listInfo);
|
|
}
|
|
protected function list_page(): array
|
|
{
|
|
if ($this->getDebug()) {
|
|
$listInfos = [
|
|
'title' => getenv("yamoon.view.test.title"),
|
|
'nickname' => getenv("yamoon.view.test.nickname"),
|
|
'detail_url' => getenv("yamoon.view.test.url"),
|
|
'time' => date("Y-m-d H:i:s"),
|
|
'hit' => 1,
|
|
];
|
|
} else {
|
|
}
|
|
$listInfos = [];
|
|
$response = $this->getMySocket()->getContent(getenv("yamoon.list.url.{$this->_category}"));
|
|
//div.bbs_item를 가진 객체를 찾아서 같은 형식의 객체(sibling)를 배열로 넘김
|
|
// log_message("debug", sprintf("\n-------------MainPage------------\n%s\n--------------------------\n", $selector->html()));
|
|
// <td class="listvisited mobile-td subject-view">
|
|
// <a href="board-read.asp?fullboardname=yamoonfreeboard&mtablename=humor&num=89372&ref=85575&page=1" class="ya-tooltip mobile-bold mobile-height" title="<p><br><br><video autoplay="autoplay" loop="loop" muted="" controls="controls" width="560"" height=" "> <source src=" https://files.bepick.net/bbs/2024/09/c2a20ab5771cbb934940551859fce1c8_769966583.mp4 "> </video><br><br><br></p">
|
|
// 졸고 있는 여군</a>
|
|
// <i class="fa fa-commenting-o" aria-hidden="true"></i> <span class="color-red small">6</span>
|
|
// <span class="visible-xs visible-sm small"><i class="fa fa-user-o" aria-hidden="true"></i> yeeyuu | <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> 6 | <i class="fa fa-eye" aria-hidden="true"></i> 369 | No 89372 | 2024-09-13</span>
|
|
// </td>
|
|
//bbs_item에서 span.g_nickname 객체를 찾아서 작성자가 "관리자" 아닌지 확인 후 Return Bool
|
|
$this->getSelector($response, getenv("yamoon.list.tag"))->each(
|
|
function (Crawler $node) use (&$listInfos): void {
|
|
$link_node = $node->filter(getenv("yamoon.list.item.link.tag"));
|
|
$detail_url = $link_node->attr("href");
|
|
$title = $link_node->text();
|
|
$info_node = $node->filter(getenv("yamoon.list.item.info.tag"));
|
|
$infos = explode("|", $info_node->text());
|
|
if (trim($infos[4]) == date("Y-m-d")) {
|
|
$listInfos[] = ['title' => $title, 'detail_url' => $detail_url, 'nickname' => trim($infos[0]), 'hit' => trim($infos[2]), 'date' => trim($infos[4])];
|
|
}
|
|
}
|
|
);
|
|
if (!count($listInfos)) {
|
|
throw new \Exception("Target URL이 없습니다.");
|
|
}
|
|
log_message("notice", __FUNCTION__ . " 작업 완료");
|
|
return $listInfos;
|
|
}
|
|
//File DB 및 Board DB 등록작업등
|
|
protected function backend_process(int $i, array $listInfo, array $storages)
|
|
{
|
|
$board_entity = $this->getMyStorage()->getBoard()->createByCrawler($i, $listInfo, $storages);
|
|
$this->getMyStorage()->getFile()->createByCrawler($board_entity, $storages);
|
|
$this->getMyStorage()->getImage()->createByCrawler($board_entity, $storages);
|
|
}
|
|
public function execute(int $max_limit): void
|
|
{
|
|
$listInfos = $this->list_page();
|
|
$this->main_process($max_limit, $listInfos);
|
|
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
|
}
|
|
}
|