Консультация № 75366
12.02.2007, 13:54
0.00 руб.
0 2 2
ВНИМАНИЕ!!! ВОПРОС!!!
Как можно средствами PHP организовать поисковую систему, или какой-нибудь веб-сервис
если можно примеры работающих сервисов разработанных с помощью PHP

ЗАРАНЕЕ - огромное спасибо за ответ.

Обсуждение

Неизвестный
12.02.2007, 14:31
общий
это ответ
Здравствуйте, Agk!

Вот несколько скриптов <u>поиска по сайту</u>:
1. Подойдет, если у Вас <b>статический</b> сайт (думаю, Вы знаете что это такое) - <a href=http://svoysite.ifolder.ru/614367>ссылка</a>
2. Для <b>любого</b> сайта - <a href=http://svoysite.ifolder.ru/1099021>вот</a>!

Удачи!

P. S. Извиняюсь, что не то, что Вам нужно.
Неизвестный
12.02.2007, 22:26
общий
это ответ
Привет , Agk! При помощи сокетов, разума и прямых рук. А еще упорства. Коннектишься к хосту по url, выкачиваешь блоками содержимое, анализируешь при помощи регулярных выражений и т.п. а дальше - на что хватит фантазии! Приложу к своему ответу более-менее иногда работающий скрипт, кот. ищет ссылки, добавляет их к себе в очередь и лезет дальше. Если ты его поймешь и доработаешь (т.е. сделаешь, чтобы он искал не только ссылки) - получится классная ИПС :)
На самом деле твой вопрос очень объемлющий. Полно на него ответить одним постом невозможно. Надо сидеть и читать статьи по ИПС. На 3 курсе у меня предмет такой был "Информационно-поисковые системы". Этот скрипт я писал на лабе по этому предмету.

Приложение:
index.php<? include_once("queue.php"); $init_queue=Array("УРЛ"); $queue = new Queue(); error_reporting(E_ALL); function download ($service, $protocol, $host, $port, $url) { $service_port = $port; $address = gethostbyname($host); $socket = socket_create(AF_INET, SOCK_STREAM, 0); if ($socket<0) { echo "socket_create() failed reason".socket_strerror($socket)."\n"; } else { //echo "OK.
"; } $result = socket_connect($socket, $address, $service_port); if ($result<0) { echo "socket_connect() failed.\n Reason: $result".socket_strerror($result); } else { //echo "OK.
"; } $in = "GET $url HTTP/1.0\r\n\r\n"; $out = ‘‘; socket_write($socket, $in, strlen($in)); $htmlpy = ‘‘; while ($out = socket_read($socket, 2048)) { $htmlpy.=$out; } socket_close($socket); return $htmlpy; } var_dump($init_queue[0]); preg_match("/^((http|ftp|mailto):\/\/)?([^\/]+)(.*)\/[^\/]*$/i", $init_queue[0], $matches); $root = $matches[1].$matches[3].$matches[4]; if (strpos($root, ‘www.cs.vsu.ru‘)) { print "root::$root

"; $htmlpy = strtolower(download(‘www‘, ‘tcp‘, ‘proxy.cs.vsu.ru‘, 3128, $init_queue[0])); preg_match_all("/<a href="([^">]*)"[^">]*>([^">]*)<\/a>/", $htmlpy, $matches); preg_match("/^((http|ftp|mailto):\/\/)?([^\/]+)(.*)\/[^\/]*$/i", $init_queue[0], $m); $depth=1; $parent = $init_queue[0]; $protocol = $m[2]; $host = $m[3]; //echo $host; $path = $m[4]; //var_dump($matches[1]); for($i=0; $i<count($matches[1]); $i++) { $url = $matches[1][$i]; preg_match("/^(http|ftp|mailto)(.*)/", $url, $matches2); if(!$matches2) { preg_match("/^(\.{2}\/?)(.*)/", $url, $matches2); if($matches2) { $url =$root."/".$macthes2[2]; } else { preg_match("/^(\.{1}\/?)(.*)/", $url, $matches2); if($matches2) { $url = $protocol."://".$host.$path."/".$matches2[2]; } else $url = $parent.$url; } } } $queue->AddtoQueue($url, $matches, $depth) ; $queue->PrintQueue(); $i=0; while ($url = $queue -> ReadUrl($queue -> marker)) { print "
$i Url to download: $url
"; $htmlpy = download(‘www‘, ‘tcp‘, ‘АДРЕС ПРОКСИ‘, 3128, $url); preg_match("/^http\/\d\.\d\s(\d{3})\s(.+)/i", $htmlpy, $matches); $status = $matches[1]; print "status: $status
"; if ($status != 200) { $queue ->status [$queue -> marker] =1; $queue -> marker++; } else { $depth = $queue -> setDepth($queue -> marker); $queue -> status[$queue -> marker] = 2; $queue -> marker++; $depth++; } preg_match_all("/<a[^ ]*\s+(class\s*=\s*[^\s]*\s*)?href\s*=\s*"?([^\s,">]*)\s*[^>]*>([^<]*)<\/a>/i", $htmlpy, $matches); preg_match("/^((http|ftp|mailto):\/\/)?([^\/]*)(.*)\/[^\/]*$/i", $url, $m); $parent = $url; if (isset($m[2])) { $protocol = $m[2]; } if (isset($m[3])) { $host = $m[3]; } if (isset($m[4])) { $path = $m[4]; } else $path = ‘‘; print "<b>host </b> : $host <b>path</b>: $path"; for ($j=0; $j<count($matches[2]); $j++) { $url = $matches[2][$j]; preg_match("/(http|mailto|ftp)(.*)/i", $url,$matches2); if(!($matches2)) { preg_match("/(\.{2}\/?)(.*)/i", $url, $mathec2); if($mathec2) { $url = $root."/".$matches2[2]; } else { preg_match("/^\/(\.{2}\/?)(.*)/i",$url ,$matches2); if($matches2) { $url = $protocol."/".$host.$path."/".$matches2[2]; } else { $url = $parent.$url; } } } echo "New.$url => ".$matches[3][$j]."
"; $queue->AddUrl($url, $matches[3][$j],$depth); } } print"
<b>Size:</b>".$queue->size."
"; $queue->PrintQueue(); }?>queue.php<? // error_reporting(E_ALL); class Queue { var $url; var $title; var $status; var $depth; var $size; var $marker; function Queue() { $this->url =array(0); $this->title =array(0); $this->status =array(0); $this->depth =array(0); $this->size =0; $this->marker =0; } function AddUrl($url, $title, $depth) { $exest= false; for($i=0; $i<$this->size; $i++) { if(!strcmp($this->url[$i],$url)) { $exest=true; break; } } if(!$exest) { if (strstr($url, ‘www.cs.vsu.ru‘)) { $this->url[$this->size]=$url; $this->title[$this->size]=$title; $this->depth[$this->size]=$depth; $this->status[$this->size]=0; $this->size++; } } } function PrintQueue() { print "<pr>Queue Size = ".$this->size."
"; print "<pr>UrlList: "; for($i=0; $i<$this->size; $i++) { //echo "<table>" print"

$i :".$this->url[$i]."=>".$this->title[$i]."\t:: Status: ".$this->status[$i]."\t:: Depth:".$this->depth[$i]; } echo "end
"; } function AddtoQueue($url, $matches, $depth) { global $queue; preg_match("/^(http:\/\/)?([^\/]+)(.*)(\/[^\/]*)?$/i", $url, $m); $host = $m[2]; $path = $m[3]; for ($j=0; $j<count($matches[1]); $j++) { $url =‘‘; $url = $matches[1][$j]; preg_match("/(http|mailto|ftp)(.*)/i", $url, $matches2); if (!$matches2[0]) { print "
$j: ".$host.$path."/".$matches[1][$j]; $url = "http://".$host.$path."/".$url; } $queue->AddUrl($url, $matches[2][$j],$depth); } } function ReadUrl($marker) { if($this->marker < $this->size) { return $this ->url[$this->marker]; } else return 0; } /*function RemoveUrl($url) { $exest= false; for ($i=0; $i<$this->size; $i++) { if(!strcmp($this->url[$i],$url)) { $exest=true; break; } } } */ function SetDepth($marker) { if ($marker == 2) { $depth++; } } }?>
Форма ответа