PullRank Home a tool to enable you to log the Google PageRank of a URL
Development History
The Code
Once I had all of the major components of PullRank in place, I discovered two timing issues that I had to resolve.

The first, mentioned before, was waiting until the document was finished loading before snapping the screen shot. To do this, I created a Boolean named loaded that was initialized to false. After I made the call to open the browser, I ran:

while (!loaded) Thread.Sleep(100);
PullRank would stay in this loop until loaded was set to true by the DocumentCompleteEventHandler. If I did not use the call to Thread.Sleep(100), then the while loop would never give up access to the loaded Boolean, in which case the event handler would never be able to change its value to true.

The second timing issue that I encountered was that sometimes a web page would finish loading before the PageRank in the Google toolbar would get updated. Thus, PullRank would return that the URL of the PageRank was undefined because that is how it appeared at the time of the screenshot. I fixed this problem by having PullRank try to get the PageRank a couple of times if it thought that the PageRank was undefined:

int pageRank = -1;
int MAX_TRIES = 2;
int tries = 0;
while (pageRank < 0 && tries < MAX_TRIES) {
  Console.WriteLine("try #" + tries);
  example.CaptureScreen(bmpFile, ImageFormat.Bmp);
  Console.WriteLine("screen shot written");
  ScreenReader reader = new ScreenReader();
  pageRank = reader.getPageRankFromFile(bmpFile);
This worked because by the time PullRank had run through this loop an extra time, the PageRank would load. I admit that this is not a robust solution; however, PullRank has to time out eventually if Google is down (God forbid!) and is not returning PageRank information to the Toolbar.



©2004 Michael Bolin » bolinfest@gmail.com www.bolinfest.com