Forum Moderators: coopster

Message Too Old, No Replies

PHP to find out Google placement?

using a keyword and domain

         

httpwebwitch

7:56 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There was a lively discussion on this a while ago. I was wondering if anyone has learned anything new.

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?

coopster

1:14 am on Jan 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There was a lively discussion on this a while ago.

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);

...then after you get the file, parse it using a REGEX. The link above discusses some details of what is going on here. You know, I'd like to think that somebody already did this though...

Anybody else?

httpwebwitch

7:15 pm on Jan 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found a way to do it.

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.

Timotheos

7:45 pm on Jan 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's cool!

Have you found the results accurate? I noticed at one tool site that their results are not always the same as when I check them on Google.

[edited by: jatar_k at 8:39 pm (utc) on Jan. 26, 2004]
[edit reason] no specific tools thx [/edit]

coopster

7:50 pm on Jan 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Cool. Thank you for the legwork and more importantly, sharing.

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 ;)

httpwebwitch

8:05 pm on Jan 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Different results in Google (using the web page) can sometimes be attributed to regional cloaking - Google (for no intelligent reason I can think of) gives slightly different results on Google.com, Google.ca, and probably other TLD's too.

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.

lasko

8:11 pm on Jan 26, 2004 (gmt 0)

10+ Year Member




coopster great read thanks.

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!

:)

Timotheos

8:13 pm on Jan 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



regional cloaking

Mmm... that must be it since it's Hungarian.