tags:

views:

61

answers:

3

Is there a way I can programmatically count the number of links for a website? Does google provide an api that can I can programmatically query?

+2  A: 

You can write a scraper (I dont recommend it though).

$page = file_get_contents('http://www.google.com/?q=link:site.com');
$page = str_replace(array('<b>', '</b>', ','), array('', '', ''), $page);

preg_match('/Results (\d+) - (\d+) of about (\d+) for/', $page, $match);

var_dump($match);
Coronatus
this will lead to captcha shown to fair users and that why I hate such an answers.
Col. Shrapnel
A: 

Maybe using the Google Ajax Search API? I'm not very familiar with it so I have no code examples but you can go here to check it out: http://code.google.com/apis/ajaxsearch/

There are also some php code examples in the documentation

Mike Gensel
A: 

Using the Zend Framework you can use find all the links on a webpage with this piece of code:

$numberOfLinks = 0
$client = New Zend_Http_Client();
$client->setUri('http://www.yoururl.com');
$response = $client->request();
if ($response->isSuccessful()) {
    $body = $response->getBody();
    $doc = Zend_Search_Lucene_Document_Html::loadHTML($body,TRUE)
    $links = $doc->getLinks();
    foreach ($links as $link) {
         $numberOfLinks++;
    }
}

The result is obviously stored in $numberOfLinks :-)

murze