Если вы нехотите платить [alexa] за статус репорт, то вот вам такой маленки хак ;)
Scrape Alexa Class
Code:
class alexa {
private $badclasses;
private $site;
private $cache;
function alexa() {
preg_match_all('#\.([a-z0-9]+) \{#i',file_get_contents('http://client.alexa.com/common/css/scramble.css'),$this->badclasses);
}
private function descramble ($matches) {
return in_array($matches[1],$this->badclasses[1])?'':$matches[2];
}
public function stats ($site, $section = 4, $item = 5) {
if (!is_array($this->cache[$site])) {
$items = array();
$html = preg_replace('# #','',preg_replace('#(?:<|<)!--.+?--(?:>|>)#','',file_get_contents('http://www.alexa.com/data/details/traffic_details/' . $site)));
preg_match_all('#</th></tr><tr>.+?</tr>#',$html,$tables);
for ($i=0,$len=count($tables[0]); $i<$len; $i++) {
preg_match_all('#<td>(.+?)</td>#',$tables[0][$i],$info);
for ($i2=0,$len2=count($info[1]); $i2<$len2; $i2++) {
$info[1][$i2] = preg_replace('#<img alt="(\w+)".+?>#','$1 ',$info[1][$i2]);
$items[$i][] = preg_replace_callback('#<span class="(.+?)">(.+?)</span>#im',array(get_class($this), 'descramble'),$info[1][$i2]);
}
}
$this->cache[$site] = $items;
}
if ($section == 4 && $item == 5) {
return $this->cache[$site];
} elseif ($item == 5) {
return $this->cache[$site][$section];
} else {
return $this->cache[$site][$section][$item];
}
}
}
использовать вот-так:
Code:
$alexa = new alexa;[/highlight][highlight=php]print_r($alexa->stats('russianamerica.com'));
print_r($alexa->stats('russianamerica.com',1));
print_r($alexa->stats('russianamerica.com',1,1));
результат
Code:
X-Powered-By: PHP/5.2.0
Content-type: text/html
Array
(
[0] => Array
(
[0] => N/A*
[1] => 0.00005%
[2] => 0.00021%
[3] => down 36%
)
[1] => Array
(
[0] => N/A*
[1] => 1,775,644
[2] => 433,279
[3] => down 137,612
)
[2] => Array
(
[0] => N/A*
[1] => 1.3
[2] => 2.8
[3] => down 3%
)
)
Array
(
[0] => N/A*
[1] => 1,775,644
[2] => 433,279
[3] => down 137,612
)
1,775,644
Да я понимаю, это не самы лутши пример, ну как говорица чем богаты :34: