Парсер Гиперкниги, частично рабочий
This commit is contained in:
parent
e0caaa00e6
commit
cdc6b0b596
1
game.php
1
game.php
|
@ -4,6 +4,7 @@ class Game {
|
||||||
public $title;
|
public $title;
|
||||||
public $author;
|
public $author;
|
||||||
public $description;
|
public $description;
|
||||||
|
public $date;
|
||||||
public function print() {
|
public function print() {
|
||||||
echo "<li><a href='$this->url'>«".$this->title."»</a> — $this->author";
|
echo "<li><a href='$this->url'>«".$this->title."»</a> — $this->author";
|
||||||
if ($this->description) {
|
if ($this->description) {
|
||||||
|
|
42
hyperbook.php
Normal file
42
hyperbook.php
Normal 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();
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
require "vendor/autoload.php";
|
require "vendor/autoload.php";
|
||||||
require "game.php";
|
require "game.php";
|
||||||
require "apero.php";
|
require "apero.php";
|
||||||
|
require "hyperbook.php";
|
||||||
require "instead.php";
|
require "instead.php";
|
||||||
require "storymaze.php";
|
require "storymaze.php";
|
||||||
use PHPHtmlParser\Dom;
|
use PHPHtmlParser\Dom;
|
||||||
|
@ -19,4 +20,5 @@ function endSection() {
|
||||||
|
|
||||||
//apero();
|
//apero();
|
||||||
//instead();
|
//instead();
|
||||||
storymaze();
|
//storymaze();
|
||||||
|
hyperbook();
|
||||||
|
|
Reference in a new issue