php класс поиска фильмов по параметрам, достаточно названия и год. Результат работы будет описание, обложка, страна, режисер, в ролях итд.
<?php
class Kinopoisk
{
// курл
var $explorer;
var $name;
var $year;
var $country;
var $cast;
var $actor;
var $film;
/**
* Конструктор
*/
public function __construct()
{
$this->explorer = new Explorer;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function setYear($year)
{
$this->year = $year;
return $this;
}
public function setCountry($country)
{
$this->country = $country;
return $this;
}
public function setCast($cast)
{
$this->cast = $cast;
return $this;
}
public function setActor($actor)
{
$this->actor = $actor;
return $this;
}
protected function parser($html)
{
$this->html = $html;
// если найдено несколько
if(preg_match('|<td width=100% class="news"><a class="all" href="(.*?)">|i', $this->html, $first)){
$this->explorer->setUrl(KINOPOISK . $first[1]);
$this->html = $this->explorer->browser();
}
if(preg_match('|<img style="border: none; border-left: 10px #f60 solid" src="(.*?)"|i', $this->html, $film_img)){
$this->film->film_img = KINOPOISK . $film_img[1];
}
if(preg_match('|<td class="type">год</td><td class="">(.*?)</td>|i', $this->html, $film_year)){
$this->film->film_year = trim(html_entity_decode(strip_tags($film_year[1])));
}
if(preg_match('|<td class="type">страна</td><td class="">(.*?)</td>|i', $this->html, $film_country)){
preg_match_all('|<a .*?>([^.].*?)</a>|i', $film_country[1], $film_country);
$this->film->film_country = $film_country[1];
}
if(preg_match('|<td class="type">режиссер</td><td>(.*?)</td>|i', $this->html, $film_director)){
preg_match_all('|<a .*?>([^.].*?)</a>|i', $film_director[1], $film_director);
$this->film->film_director = $film_director[1];
}
if(preg_match('|<td class="type">сценарий</td><td>(.*?)</td>|i', $this->html, $film_screenplay)){
preg_match_all('|<a .*?>([^.].*?)</a>|i', $film_screenplay[1], $film_screenplay);
$this->film->film_screenplay = $film_screenplay[1];
}
if(preg_match('|<td class="type">продюсер</td><td>(.*?)</td>|i', $this->html, $film_producer)){
preg_match_all('|<a .*?>([^.].*?)</a>|i', $film_producer[1], $film_producer);
$this->film->film_producer = $film_producer[1];
}
if(preg_match('|<td class="type">жанр</td><td>(.*?)</td>|i', $this->html, $film_genre)){
preg_match_all('|<a .*?>([^.].*?)</a>|i', $film_genre[1], $film_genre);
$this->film->film_genre = $film_genre[1];
}
if(preg_match('|<td class="actor_list">(.*?)</td>|is', $this->html, $film_actors)){
preg_match_all('|<span><a .*?>([^.].*?)</a></span>|i', $film_actors[1], $film_actors);
$this->film->film_actors = $film_actors[1];
}
if(preg_match('|<td class="type">время</td><td class="time" id="runtime">(.*?)</td>|i', $this->html, $film_time)){
$this->film->film_time = (int) $film_time[1];
}
if(preg_match('|<span class="_reachbanner_">(.*?)</span>|i', $this->html, $film_description)){
$this->film->film_description = trim(html_entity_decode(strip_tags($film_description[1])));
}
return $this->film;
}
public function find()
{
$this->explorer->setUrl('http://www.kinopoisk.ru/index.php?level=7'
. '&from=forma&result=adv'
. '&m_act%5Bfrom%5D=forma&m_act%5Bwhat%5D=content'
. '&m_act%5Bfind%5D=' . urlencode($this->name)
. '&m_act%5Byear%5D=' . urlencode($this->year)
. '&m_act%5Bactor%5D=' . urlencode($this->actor)
. '&m_act%5Bcast%5D=' . urlencode($this->cast)
. '&m_act%5Bcountry%5D=' . urlencode($this->country));
// задаем рефералку
$this->explorer->setReferer('http://www.kinopoisk.ru/level/7/');
$html = $this->explorer->browser();
// авторизируемся
return $this->parser($html);
}
}
------
Вызывается так
------
// обьявляем класс
$kinopoisk = new Kinopoisk;
$kinopoisk->setName('Мечта');
$kinopoisk->setYear(2006);
//$kinopoisk->setCountry();
//$kinopoisk->setCast();
//$kinopoisk->setActor();
// смотрим
print_r($kinopoisk->find());