Скрипт для сграбления ответа google
<?php $hostname = "www.google.ru";
$path = "/search?hl=ru&q=host&btnG=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA+%D0%B2+Google&lr=lang_ru";
// Заходим первый раз
$fp = fsockopen($hostname, "80") or dir("can't connect");
$out = "GET $path HTTP/1.0\r\n";
$out .="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2; .NET CLR 1.1.4322)\r\n";
$out .= "Host: $hostname\r\n";
$out .= "Connection: Close\r\n";
$out .= "\r\n";
fwrite($fp, $out);
$buffer = fread($fp, 2048);
fclose($fp);
// Находим переданные нам куки
preg_match_all("/Set-Cookie: ([^=]+)=([^;]+);/", $buffer, $matches);
$size = sizeof(@$matches[0]);
$cookie = null;
for($i = 0; $i < $size; $i++)
{
if( !is_null($cookie) )
$cookie .= "&";
$cookie .= $matches[1][$i] . "=" . $matches[2][$i];
}
$cookie .= "expires=Sun";
print $cookie;
$buffer = null;
// Заходим второй раз... и посылаем заголовок cookie:
$fp = fsockopen($hostname, "80") or dir("can't connect");
$out = "GET $path HTTP/1.0\r\n";
$out .="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MyIE2; .NET CLR 1.1.4322)\r\n";
$out .= "Host: $hostname\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie: $cookie\r\n";
$out .= "\r\n";
if(!isset($fp))
exit;
fwrite($fp, $out);
while ( !feof($fp) )
$buffer .= fread($fp, 2048);
print $buffer;
fclose($fp);
?>
Слова:
php,
script,
google
Sep. 19, 2005 // 12:32 [ permalink : LJ ]