Exemple #1
0
 /**
  * 初始化
  * @param string $start_url
  * @return string
  */
 public function init($start_url = '')
 {
     $snoopy = new Snoopy();
     $snoopy->proxy_port = "80";
     $snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
     $snoopy->rawheaders["Pragma"] = "no-cache";
     //cache 的http头信息
     $snoopy->read_timeout = 10;
     $snoopy->fetchlinks($start_url);
     log_message('debug', 'init links fetch ' . var_export($snoopy->results, true));
     //正则匹配url
     if ($snoopy->results) {
         foreach ($snoopy->results as $url) {
             if (preg_match($this->preg, $url)) {
                 $this->setUrls($url);
             }
         }
     }
     return 0;
 }
Exemple #2
0
 /**
  * KinopoiskInfo constructor.
  * @param string|null $kinopoiskLogin
  * @param string|null $kinopoiskPass
  */
 public function searchActor($actor)
 {
     /*if(count($this->auth)>0)
       {
           $this->snoopy->submit('http://www.kinopoisk.ru/level/7/', $this->auth);
           if($this->snoopy->status > 500 )
           {
               die("Error: ".$this->snoopy->response_code.", ".$this->snoopy->status);
           }
       }*/
     $url = "https://www.kinopoisk.ru/index.php?level=7&from=forma&result=adv&m_act[from]=forma&m_act[what]=actor&m_act[find]=" . $actor;
     $this->snoopy->fetch($url);
     $mainPage = $this->snoopy->results;
     $mainPage = iconv('windows-1251', 'utf-8', $mainPage);
     $pattern = '#<a href="/name/(\\d+)/sr/1/".*?data-url="(.*?)".*?class="js-serp-metrika".*?data-type="person".*?>(.*?)</a>#si';
     if (preg_match($pattern, $mainPage, $matches)) {
         if (intval($matches[1]) > 0 && !empty($matches[2]) && strpos($matches[2], $matches[1]) !== false) {
             return "https://www.kinopoisk.ru" . $matches[2];
         }
     }
     return false;
 }