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
2010-03-21 04:43:56
this will lead to captcha shown to fair users and that why I hate such an answers.
Col. Shrapnel
2010-03-21 06:37:42
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
2010-03-21 05:05:21
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
2010-03-22 10:13:09