Wednesday, September 27, 2006

Парсер MSN

<meta http-equiv="Content-Type" content="text/html"; charset="UTF-8">
<form method="post" action="index.php">
<center>
<IMG title=MSN height=33 alt=MSN
src="logo.gif" width=84>
<font size="5" color="##02218A ">Parser







</font><br>
<input type="text" name="q" size="50">
<input type="submit" name="parse" value="search"/>
</center>
</form>
<a href="http://seo-script-archive.blogspot.com/">Seo Script Archive</a>
<?php
Error_Reporting(E_ALL & ~E_NOTICE);
if ($_POST['parse']) {
parse();
}
function parse() {
//------------------Формируем URL------------------------//
$keys=file("pages.txt");
$probel=trim(str_replace(' ','%20',$_POST['q'])); // иначе курл матюкается "Bad Request"
$pages=str_replace('{KEY}',$probel,$keys);

//----------------Начинаем парсить-----------------------//
//$file=file($pages);
for ($s=0;$s<count($pages);$s++)
{
$ch = curl_init();//33
curl_setopt($ch, CURLOPT_URL, $pages[$s]); //парсим по сформированым URL'ам
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Widows NT)");
$headers = array("Cookie: SRCHHPGUSR=NEWWND=0&ADLT=OFF&NRSLT=100&NRSPH=1" ); //!!!
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
unset($file_content);
$file_content = curl_exec($ch);
//---------Ищим совпадения и выводим результат----------//

$matches = array();
preg_match_all("/<li class=\"first\">[^>]*<\/li>/U", $file_content, $matches);
for ($i=0; $i<count($matches[0]); $i++)
echo $matches[0][$i];
//flush();
}
}
?>

Создаем файл pages.txt и пишем в нем:
search.msn.com/results.aspx?q={KEY}
search.msn.com/results.aspx?q={KEY}&first=101
search.msn.com/results.aspx?q={KEY}&first=201

вот и все парсер готов.

1 Comments:

Blogger slavasmail said...

надо включить поддержку Curl для этого в в windows\php.ini найди строчку ;extension=php_curl.dll , раскоментируй ее ( убери ;)и перекинуть файлы с расширением dll вот какие толком непомню поищи в гугле.

9:07 AM  

Post a Comment

<< Home

Google
 
Web seo-script-archive.blogspot.com