Archived
1
0
Fork 0

Улучшения парсера квестбука

В основном обработка ошибок
This commit is contained in:
Alexander Yakovlev 2019-02-09 21:43:34 +07:00
parent 026e716025
commit fe4e547bef
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
2 changed files with 22 additions and 5 deletions

View file

@ -64,19 +64,31 @@ class Questbook extends Source {
public function page($url) { public function page($url) {
$game = new Game; $game = new Game;
$game->url = $url; $game->url = $url;
$game->title = $this->dom->filter('h2 a b')->first()->text(); $title = $this->dom->filter('h2 a b');
if ($title->count() > 0) {
$title = $title->first()->text();
$game->title = $title;
}
$game->platform = 'Книга-игра'; $game->platform = 'Книга-игра';
$game->description = $this->dom->filter('div.col-md-8.col-sm-12 > div > div')->reduce(function($node) { $description = $this->dom->filter('div.col-md-8.col-sm-12 > div > div')->reduce(function($node) {
if ($node->attr('style') === 'padding:5px;margin:2px;text-align:justify') if ($node->attr('style') === 'padding:5px;margin:2px;text-align:justify')
return true; return true;
return false; return false;
})->text(); });
if ($description->count() > 0) {
$description = $description->text();
$game->description = $description;
}
$game->description = trim($game->description); $game->description = trim($game->description);
$game->author = $this->dom->filter('div.col-md-8.col-sm-12 em span')->reduce(function($node) { $author = $this->dom->filter('div.col-md-8.col-sm-12 em span')->reduce(function($node) {
if ($node->attr('itemprop') === 'author') if ($node->attr('itemprop') === 'author')
return true; return true;
return false; return false;
})->text(); });
if ($author->count() > 0) {
$author = $author->text();
$game->author = $author;
}
return $game; return $game;
} }
} }

View file

@ -77,6 +77,11 @@ class Wikipage {
$pagetitle = strtr($this->game->title, [ $pagetitle = strtr($this->game->title, [
'|' => '-' '|' => '-'
]); ]);
if (empty($pagetitle)) {
echo 'ERROR: Page has no title.';
var_dump($this->game);
die();
}
$exists = $this->exists($pagetitle); $exists = $this->exists($pagetitle);
if (!$config['DRY_RUN'] && !$exists) { if (!$config['DRY_RUN'] && !$exists) {
if (!empty($this->game->image)) { if (!empty($this->game->image)) {