Парсер wordstat.yandex.ru

Иногда пригождается. Публиковал функцию на серче, потом снова потерял. Увековечу ка я ее. Итак, функции передается параметром ключевой запрос, позвращается количество запросов в месяц по wordstat.yandex.ru.

<?php
function wordstat($query) {
$query = urlencode($query);
$url = "http://wordstat.yandex.ru/advq?rpt=ppc&key=&shw=1&tm=&checkboxes=&text=$query&regions_text=%C2%F1%E5&regions=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
curl_close($ch);
preg_match_all('/<td\salign=\"right\">(.*)<\/td>/Usi', $html, $return);
if(isset($return[1][2]))
return $return[1][2];
else
return '0';
}
echo wordstat('Артур Пирожков');
?>

Добавлено много времени спустя:

Яндекс что-то подкрутил в вордстате, URL теперь другие стали + UTF-8 необходим в том же URL. Вот новая версия:

<?php
function wordstat($query) {
$query = iconv('windows-1251', 'utf-8', strtolower($query));
$url = "http://wordstat.yandex.ru/?cmd=words&geo=&page=1&text=".urlencode($query)."&text_geo=%D0%92%D1%81%D0%B5";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
curl_close($ch);
preg_match_all('/<td\salign=\"right\">(.*)<\/td>/Usi', $html, $return);
if(isset($return[1][2]))
return $return[1][2];
else
return '0';
}
echo wordstat('Артур Пирожков');
?>

h++p://php.name/php/parser-wordstatyandexru/

Оставьте первый комментарий

Оставить комментарий

Ваш электронный адрес не будет опубликован.


*


10 + 11 =