Web Hosting Talk







View Full Version : How to use Googles "link:" and other API's


Julian Jorgensen
11-04-2008, 08:25 PM
How to use Googles "link:" and other API's

Hi there!
I'm not sure if this is the correct place to ask questions about Google's API and how to combine it with PHP, but I'll see what happens! :-)
Here's the question:
How do use Google's "link" command in my programming? For example: entering "link:webhostingtalk.com" will give me following: "Results 1 - 10 of about 1,470 linking to webhostingtalk.com" .
Now, is there any way I can retrieve that number "1,470" using, for example, PHP or similar?
It might sound a bit confusing, but I'm sure the answer isn't too extensive.
Thank you so much for your time!





__________________
- Julian JorgensenWeb Hosting CanadaNon profit hosting

ThatScriptGuy
11-04-2008, 08:30 PM
I don't know how to do this with any APIs, but it would be very simple to do with a bit of screen scraping...





__________________
Kevin CacklerThat Script Guy, LLC
(501) 358-4064

Julian Jorgensen
11-04-2008, 08:35 PM
hi kevin, thanks for the quick response!... I don't have any experience with this, is it possible to give me a bit more info about screen scraping? whats the best way to do this in php?





__________________
- Julian JorgensenWeb Hosting CanadaNon profit hosting

etogre
11-04-2008, 08:45 PM
They may have an API out there to get the data easily, but here's a brute force method:
PHP Code:



<?php
function google_links($site_url = 'example.com')
{
テつ*テつ*テつ*if ($stream = fopen('http://www.google.com/search?hl=en
テつ*テつ*テつ*テつ*else
テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*return false;
テつ*テつ*テつ*テつ*
テつ*テつ*テつ*テつ*fclose($stream);
テつ*テつ*テつ*テつ*$contents = explode('Results <b>1</b> - <b>', $contents);
テつ*テつ*テつ*テつ*$contents = explode('<b>', $contents[1]);
テつ*テつ*テつ*テつ*$contents = explode('</b>', $contents[1]);
テつ*テつ*テつ*テつ*
テつ*テつ*テつ*テつ*return $contents[0];
}
echo google_links('webhostingtalk.com'); // 1,470
echo google_links('google.com'); // 626,000
?>




Works fine now but if they change anything, we're outta luck =P

Julian Jorgensen
11-04-2008, 08:50 PM
hehe thank you so much! appreciate it!





__________________
- Julian JorgensenWeb Hosting CanadaNon profit hosting