This commit is contained in:
Default
2025-04-11 23:42:59 +08:00
parent d1b2a7d5e1
commit 7ceec787f7
5 changed files with 200 additions and 18 deletions

View File

@@ -107,6 +107,16 @@ abstract class BasePage
$this->strUri = $strUri;
}
/**
* Undocumented function
*
* @return string
*/
public function getUri(): string
{
return $this->strUri;
}
/**
* Undocumented function
*
@@ -238,6 +248,4 @@ abstract class BasePage
{
return $this->Site;
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace app\task\crawler\zw630\page;
use app\model\CategoryModel;
use app\model\CountersModel;
use app\model\NovelModel;
class LatestListPage extends BasePage
{
/**
* Undocumented variable
*
* @var NovelModel
*/
protected $NovelModel;
/**
* Undocumented function
*
* @return NovelModel
*/
public function getNovelModel(): NovelModel
{
if ($this->NovelModel == NULL) {
$this->NovelModel = NovelModel::getInstance();
}
return $this->NovelModel;
}
static public $arrOptions = [
'typeMap' => [
'root' => 'array',
'document' => 'array',
'array' => 'array',
],
];
/**
* Undocumented function
*
* @return array
*/
public function getNovelFilter(): array
{
$arrFilter = [];
if ($this->isMobile()) {
$arrFilter = $this->getQueryList()->find('div.wrap-box')->eq(0)->find('ul.sort_list li')->map(function ($li) {
$strUri = $li->find('a')->eq(0)->attr('href');
return supperExtractFilename($strUri);
})->filter()->all();
} else {
$arrFilter = $this->getQueryList()->find('div.layout.layout2.layout-col2.fl ul.txt-list li')->map(function ($li) {
$strUri = $li->find('a')->eq(0)->attr('href');
return supperExtractFilename($strUri);
})->filter()->all();
}
return $arrFilter;
}
}

View File

@@ -144,7 +144,7 @@ class Site
}
/**
* Undocumented function
* retrieve novel page model
*
* @param string $strUri
* @return NovelPage
@@ -156,7 +156,7 @@ class Site
/**
* Undocumented function
* retrieve multiple novel page model
*
* @param string $strUri
* @return NovelPage[]
@@ -193,7 +193,7 @@ class Site
continue;
}
$NovelPage = new NovelPage($this, $arrItem['uri']);
$NovelPage = new NovelPage($this, $arrFilter[$intKey]['uri']);
$NovelPage->setContent($strContent);
$NovelPage->setData($arrFilter[$intKey]);
@@ -206,7 +206,7 @@ class Site
}
/**
* Undocumented function
* retrieve multiple chapter page model
*
* @param string $strUri
* @return ChapterPage[]
@@ -233,7 +233,7 @@ class Site
$strContent = $Response->getBody()->getContents();;
$ChapterPage = new ChapterPage($this, $arrItem['uri']);
$ChapterPage = new ChapterPage($this, $arrFilter[$intKey]['uri']);
$ChapterPage->setContent($strContent);
$ChapterPage->setData($arrFilter[$intKey]);
@@ -245,8 +245,48 @@ class Site
return $arrChapterPage;
}
/**
* Undocumented function
* retrieve multiple chapter page model
*
* @param string $strUri
* @return LatestListPage[]
*/
public function getLatestListPageList(array $arrFilter): array
{
/** @var LatestListPage[] */
$arrLatestListPage = [];
$arrPromises = [];
foreach ($arrFilter as $intKey => $strUri) {
$arrPromises[$intKey] = $this->getClient()->getAsync($strUri);
}
$arrResults = Promise\Utils::settle($arrPromises)->wait();
$arrSuccessfulResults = array_filter($arrResults, function ($arrResult) {
return $arrResult['state'] === 'fulfilled';
});
foreach ($arrSuccessfulResults as $intKey => $arrResult) {
$Response = $arrResult['value'];
$strContent = $Response->getBody()->getContents();;
$LatestListPage = new LatestListPage($this, $arrFilter[$intKey]);
$LatestListPage->setContent($strContent);
$arrLatestListPage[] = $LatestListPage;
}
return $arrLatestListPage;
}
/**
* download the image to the local system
*
* @param array $arrFilter
* @return void
@@ -272,8 +312,6 @@ class Site
foreach ($arrSuccessfulResults as $intKey => $arrResult) {
$Response = $arrResult['value'];
// $strContent = $Response->getBody()->getContents();
$StorageCore->writeStream($arrFilter[$intKey]['local_path'], $Response->getBody()->detach());;
}
}