Reputation: 145
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?
Upvotes: 2
Views: 259
Reputation: 4103
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 :-)
Upvotes: 0
Reputation: 11
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
Upvotes: 0
Reputation: 17977
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);
Upvotes: 1