Archived
1
0
Fork 0

Начало парсеров

This commit is contained in:
Alexander Yakovlev 2018-03-22 14:39:02 +07:00
parent 9019e9c26e
commit 90d0e020f1
3 changed files with 38 additions and 0 deletions

View file

@ -6,6 +6,7 @@ class Game {
public $author;
public $description;
public $date;
public $image;
public function print() {
$converter = new HtmlConverter();
if (STYLE === 'RUS') {

View file

@ -42,10 +42,41 @@ class Anivisual extends Source {
$link = $gameBlock->find('.novel-ttl a')[0];
$game->title = $link->innerHtml;
$game->url = 'http://anivisual.net'.$link->getAttribute('href');
$game->description = $gameBlock->find('span')->first()->text;
$games[] = $game;
$this->output .= $game->print();
}
}
public function checkPage($url) {
return (strpos($url,'http://anivisual.net/stuff/') !== FALSE);
}
public function page($url) {
$text = $this->get_text($url);
try {
$this->dom->loadStr($text, []);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
unset($text);
$game = new Game;
$game->url = $url;
$gameBlock = $this->dom->find('#casing-box');
try {
$date = trim($gameBlock->find('.icon-calendar')->first()->text);
foreach ($this->months as $ruM => $enM) {
$date = str_replace($ruM, $enM, $date);
}
$date = \DateTime::createFromFormat('d F Y', $date);
$date = $date->format('U');
$game->date = $date;
unset($date);
} catch (\Exception $e) {}
$game->title = $gameBlock->find('h1.logo')->text;
// $game->description = $this->dom->find('#content > section > span')->text;
return $game;
}
}

View file

@ -15,6 +15,9 @@ if (!isset($argv[1])) {
$url = strtolower($argv[1]);
$game = new Game;
function wikipage($game) {
var_dump($game);
}
function check($classname) {
global $game;
global $url;
@ -23,6 +26,9 @@ function check($classname) {
$cl = (new $cname());
if ($cl->checkPage($url)) {
$game = $cl->page($url);
if ($game) {
wikipage($game);
}
}
}