How to Create Google Keyword Position Checker Application?

Updated October 6, 2023
By

This article will show you how to make a simple web-application to look in google for your google keyword position, if it founds your site in the first 10,20, … 1000 places you will be notified.

This article suppose that you have medium knowledge of WhizBase so I am skipping some basic codes.

So what we need to do?

First let us make a simple form where we provide the keyword, the URL of the site we are looking for and the number of places to look in.

I am creating a default.wbsp file „this is the default file in WhizBase“.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” lang=”en” xml:lang=”en”>
<head>
<title>Google Keyword Position</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
</head>
<body >
<form name=”url_kw” action=”search.wbsp” method=”post”>
<label for=”url”>URL:</label>
<input type=”text” name=”url” id=”url” size=”55″ value=”” />
<br />
<label for=”keyword”>Keyword:</label>
<input type=”text” name=”keyword” id=”keyword” size=”35″ value=”” />
<br />
<label for=”keyword”>search in first:</label>
<select name=”max” id=”max”>
<option value=”1″>10 positions</option>
<option value=”2″>20 positions</option>
<option value=”3″>30 positions</option>
<option value=”4″>40 positions</option>
<option value=”5″>50 positions</option>
<option value=”6″>60 positions</option>
<option value=”7″>70 positions</option>
<option value=”8″>80 positions</option>
<option value=”9″>90 positions</option>
<option value=”10″>100 positions</option>
<option value=”20″>200 positions</option>
<option value=”50″>500 positions</option>
<option value=”100″>1000 positions</option>
</select>
<br />
<input type=”submit” name=”submit_button” value=”SEARCH” />
<br />
</form>
</body>
</html>

This form will submit the data we need to search.wbsp file which does the processing.

Filtering and searching

Now we will open a new file and save it as search.wbsp. In this file we need to receive the submitted information from the first file and search for the data. This script will crawl google search for the keyword provided and look for the domain name, if exists it will give back its location.

[formfields]
WB_TimeOut=0
<!–WB_BeginTemplate–>
$wbrinc[keywordPosition.ic]
$wbsetv[url|$wbv[url]]
$wbsetv[keywords|$wbv[keyword]]
$wbsetv[maxPosition|$wbv[max]]
$wbsub[KeywordPosition]
$wbsub[GetPosition]
$wbif[(“$wbgetv[indexfinal]”=”-1″) or (“$wbgetv[found]” = “false”)|Not in first $wbgetv[maxPosition] pages in search results|You are at position $wbgetv[indexfinal]]

Let me describe some code here.

WB_TimeOut=0

Is used to tell the script that there is no time-out for the request, crawling google may take time so the default time out of 30 seconds will not be enough.

$wbrinc[keywordPosition.ic]

We are including a library we will make, this is just a code management issue, it is easier if we separate the subroutines from the processing code.

$wbsetv[url|$wbv[url]]
$wbsetv[keywords|$wbv[keyword]]
$wbsetv[maxPosition|$wbv[max]]

Collection data from the POST. WhizBase do not use separate approach for post and get, it is the same. It does that work automatically in the background, so no need to filter data or worry is it get or post method.

$wbsub[KeywordPosition]
$wbsub[GetPosition]

We call the two subroutines to do the job, the first one will initialize the query, the second will search for the domain.

$wbif[(“$wbgetv[indexfinal]”=”-1″) or (“$wbgetv[found]” = “false”)|Not in first $wbgetv[maxPosition] pages in search results|You are at position $wbgetv[indexfinal]]

Finally we print the result, if we have a match we say where is it, if not we say so.

The library

Library files can not be called directly, they can only be included by another WhizBase file. In this library we have written two subroutines.

The first one will construct the query url and initialize some variables.

#* KeywordPosition start *#
#* ‘url’, ‘keywords’, ‘maxPosition’ *#
<!–wb_beginsub_KeywordPosition–>
$wbsetv[url|$WBREPL[$wbgetv[url]|http://www.||f]]
$wbsetv[url|$WBREPL[$wbgetv[url]|www.||f]]
$wbif[$wbgetv[maxPosition]<1|$wbsetv[maxPosition|1]|]
$wbsetv[indexfinal|-1]
<!–WB_EndSub–>
Next the subroutine doing the work:
#* GetPosition start *#
<!–wb_beginsub_GetPosition–>
$wbif[(“$wbgetv[url]” <> “”) && (“$wbgetv[keywords]” <> “”)|
$wbsetv[make_url|http://www.google.com/search?hl=en&q=$wbesc[$wbgetv[keywords]]&start=]
$wbsetv[index|0]
$wbsetv[found|false]
$wbsetv[page|0]
$wbwhile[($wbgetv[page]<$wbgetv[maxPosition]) and (“$wbgetv[found]” = “false”)|
$wbsetv[results$wbgetv[page]|0]
$wbsetv[contains|]
$wbsetv[contains|$WBGETURL[$wbgetv[make_url]$wbgetv[page]0]]
$WBRXE[$wbgetv[contains]|a href=”($wbfn[chr(91)]^”$wbfn[chr(93)]+)” class=l.+?>.+?<\/a>|results$wbgetv[page]|t|t|f]
$wbsetv[counter|0]
$wbwhile[($wbgetv[counter]<$WBALEN[results$wbgetv[page]]) and (“$wbgetv[found]” = “false”)|
$wbsetv[link|$wbgetv[results$wbgetv[page]($wbgetv[counter])]]
$wbsetv[index|$wbcalc[$wbgetv[index]+1]]
$wbif[$WBINDOF[$wbgetv[link]|$wbgetv[url]]>0|$wbsetv[found|true]|]
$wbsetv[counter|$wbcalc[$wbgetv[counter]+1]]
]

$wbsetv[page|$wbcalc[$wbgetv[page]+1]]
]
$wbsetv[indexfinal|$wbgetv[index]]
|
]
<!–WB_EndSub–>

Let me explain some codes here:

$wbsetv[make_url|http://www.google.com/search?hl=en&q=$wbesc[$wbgetv[keywords]]&start=]
$wbsetv[index|0]
$wbsetv[found|false]
$wbsetv[page|0]

The first line can be changed, it depends on Google’s search url, the part we need is after „&q=“.  Index variable start with 0, and by default we suppose that we do not have a location and we start with page number 0.

$wbwhile[($wbgetv[page]<$wbgetv[maxPosition]) and (“$wbgetv[found]” = “false”)|
We start a while loop, we need to loop through pages and as long as found is false.
$wbsetv[contains|$WBGETURL[$wbgetv[make_url]$wbgetv[page]0]]

In this code we get all the HTML content of this page and submit it in contains variable. $WBGETURL calls any url we provide to it it fetchs all the source code we can see in our browser.

$WBRXE[$wbgetv[contains]|a href=”($wbfn[chr(91)]^”$wbfn[chr(93)]+)”.+?>.+?<\/a>|results$wbgetv[page]|t|t|f]

$WBRXE will go through our source code and get all regular expression matching for this pattern „a href=”($wbfn[chr(91)]^”$wbfn[chr(93)]+)”.+?>.+?<\/a>“, these are all the links in google result page. We put our result in results# as an array where # is the number of the page we are in.

$wbwhile[($wbgetv[counter]<$WBALEN[results$wbgetv[page]]) and (“$wbgetv[found]” = “false”)|

Now we loop through our array to look for our domain.

$wbif[$WBINDOF[$wbgetv[link]|$wbgetv[url]]>0|$wbsetv[found|true]|]

Finally we look if in the link is our domain, if yes we set found as true and that will break the two loops and return all data needed.

Save the full code above as „keywordPosition.ic“, and you have a basic script for searching domain’s position in google search for a keyword.

Download the full script from SourceForge.net

About the author:- Ashraf Gheith is a PHP and WhizBase programmer, who at the time of article publication is working in partnership with WhizBase on several projects. You can visit his site on http://www.small-applications.com

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts
Search Here
Explore Laptops on DHgate