
04.05.2010, 13:53
|
|
Members of Antichat - Level 5
Регистрация: 15.06.2008
Сообщений: 941
Провел на форуме: 5111568
Репутация:
2399
|
|
модуль из одного довольно большого парсинг-движка:
PHP код:
// itspoma, 12.04.2010
class google
{
public $pages = 0;
public $try = 0;
function parse($q, $page = 0) {
global $config;
$count_inpage = rand(41,59);
$offset = $page*$count_inpage;
$google_page = curl('http://www.google.com/search?hl=ru&q='.urlencode($q).'&start='.$offset.'&num='.$count_inpage.'&');
debug($google_page, 'google_page'.($page+1));
if (stristr($google_page, '>Sorry...<'))
{
sleep(10);
$page += rand(1,4);
$this->try++;
if ($this->try <= 3) {
return $this->parse($q.' ', $page);
}
return array();
}
$links = array();
$temp_links = array();
preg_match_all('/<h3 class=r><a href="(.+?)"/is', $google_page, $temp_links);
ar_push_ar($links, $temp_links[1]);
preg_match_all('/<a href="\/url\?q=(.+?)[&|"]+/is', $google_page, $temp_links);
ar_push_ar($links, $temp_links[1]);
if ($config['debug'] == True)
echo '<b><font color=red>page '.($page+1).'</b></font> '.count($links).'<br/>';
if (stristr($google_page,'&start='.(($page+1)*$count_inpage))) {
if ($this->pages-1 > 0 && $page >= $this->pages-1) {
return $links;
}
$temp_links = $this->parse($q, $page+1);
ar_push_ar($links, $temp_links);
}
return $links;
}
}
// ф-ция для добавления масива в другой масив
function ar_push_ar(&$a,$b)
{
foreach($b as $el)
{
array_push($a, $el);
}
}
юзать:
PHP код:
$g = new google();
$g->pages = 3;
$links = $g->parse('antichat');
var_dump( $links );
|
|
|