Archived
1
0
Fork 0

Парсер Гиперкниги, частично рабочий

This commit is contained in:
Alexander Yakovlev 2017-01-22 12:00:56 +07:00
parent e0caaa00e6
commit cdc6b0b596
3 changed files with 46 additions and 1 deletions

View file

@ -4,6 +4,7 @@ class Game {
public $title;
public $author;
public $description;
public $date;
public function print() {
echo "<li><a href='$this->url'>«".$this->title."»</a> — $this->author";
if ($this->description) {

42
hyperbook.php Normal file
View file

@ -0,0 +1,42 @@
<?php
function hyperbook() {
global $dom, $period, $formatter;
startSection("Гиперкнига");
$dom->loadFromUrl('http://hyperbook.ru/lib.php?sort=time');
$container = $dom->find('#listPubs');
$games = [];
foreach ($container->find("h3") as $heading) {
$game = new Game;
$link = $heading->find('a')[0];
$game->title = $link->innerHtml;
$game->url = $link->getAttribute('href');
$games[] = $game;
}
$i = 0;
foreach ($container->find("div") as $author) {
if ($author->getAttribute('style') !== 'text-align:left;margin-bottom:4px;') {
continue;
}
$games[$i]->author = $author->innerHtml;
$i++;
}
$i = 0;
foreach ($container->find("div.small") as $small) {
if($small->getAttribute('style') === 'float: left; width: 20%; text-align:right;') {
$games[$i]->date = $small->innerHtml;
}
if($small->getAttribute('class') === FALSE) {
$games[$i]->description = $small->innerHtml;
$i++;
}
}
foreach ($games as $game) {
$date = DateTime::createFromFormat('d.m.y', $game->date);
if ($date === false) continue;
$date = $date->format('U');
if ($date < $period) continue;
$game->print();
}
endSection();
}

View file

@ -2,6 +2,7 @@
require "vendor/autoload.php";
require "game.php";
require "apero.php";
require "hyperbook.php";
require "instead.php";
require "storymaze.php";
use PHPHtmlParser\Dom;
@ -19,4 +20,5 @@ function endSection() {
//apero();
//instead();
storymaze();
//storymaze();
hyperbook();