Вот ещё раз целиком весь код разбора заглавной страницы
http://uletno.net и добавления её как сервиса.
Сложно ли это?
Код: Выделить всё
<?php
#############################################################################
# Author: consros 2011 #
# Author: stalker 2011 #
#############################################################################
require_once 'interfaces/service.inc';
require_once 'interfaces/channel.inc';
require_once 'interfaces/item.inc';
require_once 'interfaces/pager.inc';
require_once 'interfaces/message.inc';
require_once 'tools/http.inc';
require_once 'tools/logger.inc';
require_once 'tools/parser.inc';
require_once 'tools/config.inc';
class UletnoService extends Service {
protected $log;
protected $http;
public function init(&$cfg, &$lang) {
parent::init($cfg, $lang);
$this->log = Logger::getLogger(get_class());
$this->http = new HttpTools();
$this->log->setLevel(5);
$this->log->setFilepath(null);
}
public function startPage() {
$page = $this->getOptionalParam('page', 1);
$url = 'http://uletno.info/page/' . $page . '/';
$html = $this->http->sendGetRequest($url);
# cut off not necessary parts
$html = ParserTools::parseParam($html, "<div id='dle-content'>", '<form method="post"');
# $this->log->debug('HTML: ' . print_r($html, true));
# convert from cp-1251 to utf-8 accepted by us
$html = iconv('Windows-1251', 'UTF-8', $html);
# split on movie describing blocks
$movies = ParserTools::parseTokens($html, 'id="table11"', 'id="table18"');
# $this->log->debug('HTML: ' . print_r($movies, true));
$channel = new Channel('Uletno.info', '', '');
$channel->setSupportedTemplates('wall', 'icon-table', 'detailed-list');
$url = $this->cfg->get('service_url') . '&req=details&id=';
foreach ($movies as $movie) {
$name = ParserTools::parseParam($movie, 'class="roltitle">', ' смотреть');
$thumb = ParserTools::parseParam($movie, '<img src="/uploads/posts', '"');
$descr = ParserTools::parseParam($movie, 'style="display:inline;">', '<a href');
$id = ParserTools::parseParam($movie, 'align: top;"><a href="', '"');
# make absolute path to image
$thumb = 'http://uletno.info/uploads/posts' . $thumb;
# remove html tags from used fields
$name = ParserTools::removeHtmlTags($name);
$descr = ParserTools::removeHtmlTags($descr);
$item = new Item($name, $descr);
$item->set(Item::ID, $id);
$item->set(Item::THUMBNAIL, $thumb);
$item->set(Item::LINK, $url . urlencode($id));
$channel->addItem($item);
}
return $channel;
}
public function details() {
# id = url in our case
# e.g. http://uletno.info/2011/10/05/sent-anzh.html
$url = $this->getRequredParam('id');
$html = $this->http->sendGetRequest($url);
# cut off not necessary parts
$html = ParserTools::parseParam($html,
'Get Adobe Flash player', '<table class="storyfinfo"');
# convert from cp-1251 to utf-8 accepted by us
$html = iconv('Windows-1251', 'UTF-8', $html);
# main params
$name = ParserTools::parseParam($html, '"comment":"', '"');
$video = ParserTools::parseParam($html, '"file":"', '"');
$descr = ParserTools::parseParam($html,
'style="display:inline;">', '</div>');
# remove html tags from used fields
$name = ParserTools::removeHtmlTags($name);
$descr = ParserTools::removeHtmlTags($descr);
$channel = new Channel($name, '', $descr);
# $channel->setSupportedTemplates('media-details');
$channel->setSupportedTemplates('auto-open');
$item = new Item($name, '');
$item->addEnclosure($video, 'video/mp4');
$channel->addItem($item);
return $channel;
}
}
?>