Archived
1
0
Fork 0
This repository has been archived on 2020-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
news-script/Source/Apero.php

39 lines
1.5 KiB
PHP

<?php
namespace Source;
use \Game;
/**
* Парсер для Apero.ru
* Проблема парсера в том, что на Аперо часто поломана кодировка UTF-8.
*/
class Apero extends Source {
public $title = "Apero";
protected function parse() {
$text = $this->get_text('http://apero.ru/Текстовые-игры/Песочница');
$text = mb_convert_encoding($text, 'UTF-8', 'auto');
$this->dom->loadStr($text, []);
$this->parsePage();
$text = $this->get_text('http://apero.ru/Текстовые-игры');
$text = mb_convert_encoding($text, 'UTF-8', 'auto');
$this->dom->loadStr($text, []);
$this->parsePage();
}
protected function parsePage()
{
$formatter = new \IntlDateFormatter( 'ru', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE );
$games = $this->dom->find('.tabled-game-block');
foreach ($games as $gameBlock) {
$date = trim($gameBlock->find('.game-updated-block')->innerHtml, "() \t\n\r\0\x0B");
$date = $formatter->parse($date);
if ($date < $this->period) continue;
$game = new Game;
$game->author = trim($gameBlock->find('.game-author-block')[0]->find('a')->innerHtml);
$game->title = trim($gameBlock->find('h2')[0]->find('a')[0]->innerHtml);
$game->url = trim($gameBlock->find('h2')[0]->find('a')[0]->getAttribute('href'));
$game->description = trim($gameBlock->find('.game-desc-block')[0]->innerHtml);
$this->output .= $game->print();
}
}
}