[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Парсинг поисковой выдачи
777gum
Объясните мне, как олуху:
заказал скрипт, по глупости на хостинге не проверил.
На локал хосте (php 5.2) (windows) - всё идеально работает.
А на хостинге(vps centos) пишет что ошибка в 71ой строке

<?php 

class Yandex

{

private function check($filename)
{
return file_exists($filename.".txt");
}

private function read($filename)
{
$handle = fopen($filename.".txt", "r");
$content = fread($handle, filesize($filename.".txt"));
fclose($handle);

return explode("\n", $content);
}

private function save($filename, $content)
{
$content = $content['title']."\r\n".$content['description'];
$fp = fopen($filename.".txt", 'w+');
fwrite($fp, $content);
fclose($fp);
}

private function __get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_ENCODING,'gzip,deflate');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; ru:1");
curl_setopt($ch, CURLOPT_COOKIEFILE, "./cook.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "./cook.txt");
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

# Функция парсинга выдачи из Yandex.
public function Start($string, $language = 'ru', $count = 10)
{
$query = urlencode(mb_strtolower($string, 'UTF-8'));

if($this->check($query)) {
$snippet = $this->read($query);
$snippets['title'] = $snippet[0];
$snippets['description'] = $snippet[1];

return $snippets;
} else {

$url = "http://yandex.ru/yandsearch?text=$query&lang=$language&lr=213";
$html = $this->__get($url);

$snippets = array();
$t = '';

if (!is_bool($html))
{
$description = '';
preg_match('|<a.*class="b-serp-item__title-link".*>(.*)</a>|Uis', $html, $title);
preg_match_all('|<div.*class="b-serp-item__text".*>(.*)</div>|Uis', $html, $results);
foreach($results[1] as $result) {
$description .= strip_tags($result)." ";
}
$title[1] = preg_replace("/([wW]{3,3}\.|)[A-Za-z0-9]+?\.(net|org|com|ru|su|рф)/i", "", $title[1]);
$description = preg_replace("/([wW]{3,3}\.|)[A-Za-z0-9]+?\.(net|org|com|ru|su|рф)/i", "", $description);
$snippets['title'] = strip_tags($title[1]);
$snippets['description'] = $description;
$this->save($query, $snippets);
}
}


return $snippets;
}
}



<!doctype html>
<html>
<head>
<meta
charset="utf-8">
<title>
Документ без названия</title>
</head>

<body>
<?php

require_once("yandex.php");
$yandex = new Yandex();
$results = $yandex->Start("запрос для ПС");
?>
<?php
echo $results["title"]; ?>
<?php
echo $results["description"]; ?>
</body>
</html>




Что не так?
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.