Forum Moderators: coopster
I'd like to use PHP to find out how high our site gets on certain key words. There are shareware programs that do this, but I'd enjoy being able to do the same thing using PHP on a web page.
Is it possible to "suck" in the first X pages of SERPS, parse them, and find out where our site sits?
Where? :) I'd like to read it.
Brainstorming out loud...You could create your own PHP <form> script that would allow you to key in values, build the GET string that Google builds, then open that file (URL) with PHP's fopen() function. Then you would need to parse the file into usable arrays of rank and URL...probably with a regular expression...
$keywords = (isset($_POST['keywords']))? $_POST['keywords'] : '';
// assuming you separated your keywords with a single space:
$keywords = urlencode(str_replace(' ', '+', $keywords));
$url = 'http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q='
. $mykeywords .
'&btnG=Google+Search';
$fp = fopen($url, "r");
$data = fread($fp, 30*1024); // jatar_k, does that equal 30000? [webmasterworld.com]
fclose($fp);
Anybody else?
Google (recently) opened up their API with SOAP. It's possible to query Google and get a SOAP reply, which can then be parsed as an array, and checked for the domain using a regex.
To do it, you need 3 things:
1) apply for a Google Developer token
2) the "nuSOAP" classes (available for free)
3) this code:
include("/SOAP/nusoap.php");$soapclient = new soapclient("http://api.google.com/search/beta2");
$wordval="free gadgets";
$startat = 0;
$params = array(
'key'=> 'put_your_key_here', // Google license key
'q' => $wordval, // search term
'start' => $startat, // start from result n
'maxResults' => 10, // show a total of n results
'filter' => false, // remove similar results
'restrict' => '', // restrict by topic
'safeSearch' => false, // remove adult links
'lr' => '', // restrict by language
'ie' => '', // input encoding
'oe' => '' // output encoding
);
$result = $soapclient->call("doGoogleSearch", $params, "urn:GoogleSearch", "urn:GoogleSearch");
once you get your $result back from Google, print it with print_r($result) to see how it's structured, and grab the bits you want out of it.
Using this method, I was able to make a custom script that checks a page's placement in the SERPs using important key words.
I'm assuming the related link is h**p://www.google.com/apis/api_faq.html?
Anyone interested can check out a SOAP tutorial at Zend:
Web Services with NuSOAP
URL: h**p://www.zend.com/zend/tut/tutorial-campbell.php
unless lorax [webmasterworld.com] has one ready for us yet ;)
I live & work in Canada. My address bar says "google.com", but Google is giving me results that are different from those given to my comrades in the US. While my SERPs say that our site is #1, they'll say it's #3.
The google results from the API interface have been totally accurate in all my tests so far; they reflect the SERPs on Google.com in the USA.
My affiliate supplier has now provided us with xml feed using SOAP UDL and something else. This would allow us to access their database in real time.
have not got a clue where to start, I am an advanced novice php programmer using Mysql and have been reading a lot about xml and the power of feeds etc.
I don't want to go off topic but it does seem like this is the direction we are all heading and it would be nice to see more info here about SOAP, XML feeds etc at WW.
I think its quite heavy stuff for me at the moment however thats what I thought about php when I first started.
Everyday you learn something new!
:)