
26.02.2008, 02:53
|
|
Флудер
Регистрация: 20.11.2006
Сообщений: 3,316
Провел на форуме: 16641028
Репутация:
2371
|
|
PHP код:
Google Parser by lamarez
IcQ:123424
Site:k0x.ru
Use: php gp.php -q "your query" [-title] [-page ...]
-help This help:).
-q Your query.
-page Page number.
-num count of results.
-title Show page title.
Search pages with word "lamarez"
Example: php gp.php -q "lamarez"
Show 100 links of sites with word "lamarez" and their titles.
Example: php gp.php -q "lamarez" -num 100 -title
PHP код:
<?
//error_reporting(0);
function GetSome($domain, $path)
{
$hostname = gethostbyname($domain);
$responce = "";
$errnum=0;$errstr="";
$fsock = fsockopen($hostname,80,$errnum,$errstr,5);
if(!$fsock)
{
return 0;
}
$headers = "GET $path HTTP/1.1\n";
$headers .= "Host: $domain\n";
$headers .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2\n";
$headers .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\n";
$headers .= "Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3\n";
$headers .= "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7\n";
$headers .= "Keep-Alive: 500\r\n\r\n";
fwrite ($fsock,$headers);
while (!feof($fsock))
{
$responce .= fread($fsock,1024);
}
fclose ($fsock);
return $responce;
}
function GetCLI($str)
{
echo iconv("WINDOWS-1251","CP866",$str);
$line = trim(fgets(STDIN));
return $line;
}
if(!isset($argv))
{
die("Work only in console. Use: php gp.php");
}
if(in_array('-help',$argv))
{
$helptext = "Google Parser by lamarez\n"
."IcQ:123424\n"
."Site:k0x.ru\n\n"
."Use: php gp.php -q \"your query\" [-title] [-page ...]\n\n"
."-help This help:).\n"
."-q Your query.\n"
."-page Page number.\n"
."-num count of results.\n"
."-title Show page title.\n\n"
."Search pages with word \"lamarez\"\n"
."\tExample: php gp.php -q \"lamarez\"\n"
."Show 100 links of sites with word \"lamarez\" and their titles.\n"
."\tExample: php gp.php -q \"lamarez\" -num 100 -title\n";
die($helptext);
}
////////////////////////////////////////////////////////////
if(in_array('-page',$argv))
{
$page = $argv[array_search('-page',$argv)+1];
}
else
{
$page = 0;
}
////////////////////////////////////////////////////////////
if(in_array('-num',$argv))
{
$num = $argv[array_search('-num',$argv)+1];
}
else
{
$num = 10;
}
////////////////////////////////////////////////////////////
if(in_array('-q',$argv))
{
$query = $argv[array_search('-q',$argv)+1];
}
else
{
$query = GetCLI('Введите строку для поиска:');
}
$title = (in_array("-title",$argv))?true:false;
$cool = (in_array("-beautiful",$argv))?true:false;
////////////////////////////////////////////////////////////
$query=urlencode($query);
//$googletext=GetSome('www.google.com',"http://www.google.com/search?q=$query&num=$num&hl=ru&client=opera&rls=ru&start=".($page*$num)."&sa=N");
$googletext=file_get_contents("http://www.google.com/search?q=$query&num=$num&hl=ru&client=opera&rls=ru&start=".($page*$num)."&sa=N");
$googletext=str_replace('<b>','',$googletext);
$googletext=str_replace('</b>','',$googletext);
preg_match_all('#<a href="(\S+)" class=l>([^<]*)</a>#i',$googletext,$zret);
for($i=0;$i<count($zret[1]);$i++)
{
if($cool){echo "--------------------------------------------------------------------------------\n";}
if($title)
{
$titletext = htmlspecialchars_decode($zret[2][$i]);
$titletext = iconv("WINDOWS-1251","CP866",$titletext);
echo "\t".$titletext."\n";
}
echo $zret[1][$i]."\n";
if($cool){echo "--------------------------------------------------------------------------------\n";}
}
?>
можна просто php script.php а затем через stdin ввести что нужно искать...
а можна php script.php -num 100 -title -page 2 и опятьже ввести через stdin...
© lamarez gay
|
|
|