Google Rank Checker

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Google Rank Checker

Post by Marcus Tettmar » Mon Jun 12, 2006 9:17 am

Note: This was written in 2006. Since then Google has no doubt changed drastically. Furthermore the legacy code in this post has been superseded and it will not work in the latest version without an old version of WebRecorder. I would now recommend a different approach such as this: http://www.mjtnet.com/blog/2013/10/03/a ... ng-google/

A Google Rank Checker. Enter a search term and URL and the script will determine the position of the URL in the Google search results for that search term.

This script uses the WebRecorder IEAuto.DLL library to manipulate Google in Internet Explorer and parse the search results. It demonstrates how WebRecorder can be used to automate web pages and analyse the source.

Code: Select all

/*
Google Rank Checker
Copyright 2008 MJT Net Ltd

Updat 9th August 2008: Updated for recent changes to Google html

*/

Dialog>Dialog1
   Caption=Google Rank Checker
   Width=346
   Height=226
   Top=CENTER
   Left=CENTER
   Max=0
   Min=0
   Close=1
   Resize=0
   Label=Search Term:,8,16,true
   Label=URL:,8,48,true
   Label=Number of Pages to Scan:,8,88,true
   Edit=txtSearch,96,16,225,
   Edit=txtURL,96,48,225,
   Edit=txtNumPages,144,80,33,5
   Button=OK,160,120,75,25,4
   Button=Cancel,248,120,75,25,2
   CheckBox=msCheckBox1,Hide IE,256,80,65,False
   Button=Built with Macro Scheduler,8,160,321,25,0
   Default=OK
EndDialog>Dialog1

Label>start
Show>Dialog1,r
If>r=20
  ExecuteFile>http://www.mjtnet.com/
  Goto>end_script
Endif
If>r=2,end_script

If>{(%Dialog1.txtSearch%="") OR (%Dialog1.txtURL%="")}
  MessageModal>Please enter a search term and URL
  Goto>start
Endif

Let>PagesToScan=Dialog1.txtNumPages
Let>Keywords=Dialog1.txtSearch
Let>URLToFind=Dialog1.txtURL

LibLoad>IEAuto.dll,hIE
If>hIE=0
  MessageModal>Could not load IEAuto.dll, make sure it is in the path or edit the LibLoad line.
  Goto>end_script
EndIf

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0
Let>delay=1

LibFunc>hIE,CreateIE,IE[0],0

if>Dialog1.msCheckBox1=True
  LibFunc>hIE,ShowIE,r,IE[0],0
Endif

//Go to Google.com
LibFunc>hIE,Navigate,r,%IE[0]%,http://www.google.com/advanced_search?hl=en
LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay

//Enter a search term
Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"as_q"}
Let>FieldValue=Keywords
LibFunc>hIE,FormFill,r,%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

//Set to 10 results per page
Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"num"}
Let>FieldValue={"10 Results"}
LibFunc>hIE,FormFill,r,%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

//Set to Englisg
Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"lr"}
Let>FieldValue={"English"}
LibFunc>hIE,FormFill,r,%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,submit

LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay

//Scan through all texts looking for results ....
Let>rank=0

Let>IsFound=0
Let>PagesDone=0
Label>ScanPage

Let>p=0
Label>scan
  Let>P%p%_SIZE=4098
  Let>P%p%=DUMMY
  LibFunc>hIE,ExtractTag,r,%IE[0]%,,SPAN,p,0,P%p%
  MidStr>r_6,1,r,this

  Let>rank=rank+1
  //Diagnostic showing results as scanned
  //MessageModal>Pos %rank%: %this%
  Pos>URLToFind,this,1,IsFound
  If>IsFound>0
      MessageModal>Found %URLToFind% in Position: %rank%
     Goto>Finish
  Endif
  Let>p=p+1
  If>p<10,scan
Label>end_scan

//Click the Next button
Let>FrameName={""}
Let>FormName={"f"}
Let>TagValue={"Next"}
LibFunc>hIE,ClickTag,r,%IE[0]%,str:FrameName,str:FormName,A,TEXT,str:TagValue
LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay

Let>PagesDone=PagesDone+1
//Loop back and do next page if required 
If>PagesDone<PagesToScan,ScanPage

Label>Finish
//Comment next line out if you don't want IE to close
LibFunc>hIE,KillIE,r,IE[0]

If>IsFound=0
  Ask>%URLToFind% Not Found in Search Results. Try again?,restart
  If>restart=YES
    Goto>start
  Endif
Endif

LibFree>hIE
Label>end_script
Notes and caveats: The script uses the advanced search page to ensure the language is set to English. It uses some simple rules about the format of the returned page in order to locate search results. It looks for lines containing the phrase " - Similar pages". These lines contain the resultant URLs. Such rules are required as Google is dynamic in nature (you cannot predict how many sponsored links will appear) and there is no specific tag identifying the start of the organic results. Looking for "- Similar pages" works in all our test cases. Should the layout or format of Google change, the script may need tweaking! If you are really serious about writing a Google Rank Checker you would be better off checking out the Google APIs. But this script shows what is possible with some basic WebRecorder/Macro Scheduler coding and demonstrates how driving the front end can often bypass more complicated solutions.

If you do not have Macro Scheduler you can download a compiled version of this script here:

http://www.mjtnet.com/software/GoogleRankCheck.zip

This includes an evaluation version of the IEAuto.DLL library.

Updated: August 2008 for recent changes to Google HTML
Last edited by Marcus Tettmar on Sat Mar 29, 2014 2:21 pm, edited 8 times in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Scheduled Google Position Checker with CSV Output

Post by Marcus Tettmar » Mon Jun 12, 2006 10:28 am

Here's a variation on the above script. This one works hidden, in batch mode and takes a series of search terms from a text file. The results are stored in a CSV file with the date. This would be ideal as a daily schedule, resulting in a CSV file which can be opened in Excel and charted.

Code: Select all

Let>InputFile=%SCRIPT_DIR%\GooglePosChecker.txt
Let>OutputFile=%SCRIPT_DIR%\GoogleResults.csv
ReadLn>InputFile,1,URLToFind
ReadLn>InputFile,2,PagesToScan

LibLoad>%SCRIPT_DIR%\IEAuto.dll,hIE
If>hIE=0
  MessageModal>Could not load IEAuto.dll, make sure it is in the path or edit the LibLoad line.
  Goto>end_script
EndIf

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0
Let>delay=1

//Create an IE window and HIDE it
LibFunc>hIE,CreateIE,IE[0],0
LibFunc>hIE,ShowIE,r,IE[0],0

Year>yy
Month>mm
Day>dd

Let>k=2
Label>start
Let>k=k+1
ReadLn>InputFile,k,Keywords
If>Keywords=##EOF##,end_script
Message>Please wait...%CRLF%Searching: %Keywords%

//Go to Google.com
LibFunc>hIE,Navigate,r,%IE[0]%,http://www.google.co.uk/advanced_search?hl=en
LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay

//Enter a search term
Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"as_q"}
Let>FieldValue=Keywords
LibFunc>hIE,FormFill,r,%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

//Set to 10 results per page
Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"num"}
Let>FieldValue={"10 Results"}
LibFunc>hIE,FormFill,r,%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,0

//Set to Englisg
Let>FrameName={""}
Let>FormName={"f"}
Let>FieldName={"lr"}
Let>FieldValue={"English"}
LibFunc>hIE,FormFill,r,%IE[0]%,str:FrameName,str:FormName,str:FieldName,str:FieldValue,submit

LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay

//Scan through all texts looking for results ....
Let>rank=0

Let>IsFound=0
Let>PagesDone=0
Label>ScanPage

Let>p=0
Label>scan
  Let>P%p%_SIZE=4098
  Let>P%p%=DUMMY
  LibFunc>hIE,ExtractTag,r,%IE[0]%,,SPAN,p,0,P%p%
  MidStr>r_6,1,r,this
  Let>rank=rank+1
  //Diagnostic showing results as scanned
  //MessageModal>Pos %rank%: %this%
  Pos>URLToFind,this,1,IsFound
  If>IsFound>0
	  //MessageModal>Found %URLToFind% in Position: %rank%
	  Goto>Finish
  Endif
  Let>p=p+1
  Pos>Result Page:,this,1,en
  If>p<10,scan
Label>end_scan

//Click the Next button
Let>FrameName={""}
Let>FormName={"f"}
Let>TagValue={"Next"}
LibFunc>hIE,ClickTag,r,%IE[0]%,str:FrameName,str:FormName,A,TEXT,str:TagValue
LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay

Let>PagesDone=PagesDone+1
//Loop back and do next page if required 
If>PagesDone<PagesToScan,ScanPage

Label>Finish

If>IsFound=0
   Let>rank=0
Endif

//MessageModal>%Keywords%;%rank%
WriteLn>outputfile,r,%yy%%mm%%dd%;%Keywords%;%rank%

Goto>start

Label>end_script
LibFunc>hIE,KillIE,r,IE[0]
LibFree>hIE
Message>Done
Run>Notepad %outputfile%
An example input file:

http://www.mjtnet.com
10
windows macro
windows automation
automated software testing
windows scripting

The first line is the URL to look for. The second line the number of pages to check and the subsequent lines list the search phrases.

Example output:

20060612;windows macro;1
20060612;windows automation;5
20060612;automated software testing;38
20060612;windows scripting;44
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts