Overcoming Personalized Search Rank Tracking

February 19, 2010

image link is broken
image

To upgrade our systems for the current personalized search systems and the future changes that are sure to come in 2010, we have developed a Python-based monitoring system that uses the APIs and AJAX request system in place at Google, Yahoo and Bing.

The values being pulled are what we consider the baseline rank before regional and personalized value is applied to the results (which is what you and your clients see when using the web frontend to the search engines in question).

For Python developers:

This was developed using Python 2.4, but the imported packages should apply seamlessly to 2.4 or greater. Please leave notes and ideas below so we can modify this and get a better system for everyone.

import re
import sys
import pprint
import urllib, urllib2
import simplejson as json

class RankChecker:

    def __init__(self, keyword, domain):
        self.keyword = keyword
        self.RE_OBJ = re.compile(domain)

        self.YAHOO_APP_CODE = 'YOUR CODE'
        self.BING_APP_CODE = 'YOUR CODE'

    def __googleFlag__(self):
        self.URL_PREPEND = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='
        self.URL_APPEND = ''
        self.ITER_NAME = 'start'
        self.ADDED_PARAMS = ['&safe=off','&rsz=large']
        self.ITER_FUNC = lambda x: x * 8
        self.LOOP_POINT = lambda x: x['responseData']['results']
        self.RESULT_NODE = 'url'

    def __yahooFlag__(self):
        self.URL_PREPEND = 'http://boss.yahooapis.com/ysearch/web/v1/'
        self.URL_APPEND = '?appid=' + urllib.quote(self.YAHOO_APP_CODE) + '&format=json'
        self.ITER_NAME = 'start'
        self.ADDED_PARAMS = ['&count=10']
        self.ITER_FUNC = lambda x: x * 10 + 1
        self.LOOP_POINT = lambda x: x['ysearchresponse']['resultset_web']
        self.RESULT_NODE = 'url'

    def __bingFlag__(self):
        self.URL_PREPEND = 'http://api.search.live.net/json.aspx?Appid=' + urllib.quote(self.BING_APP_CODE) + '&Sources=Web&query='
        self.URL_APPEND = ''
        self.ITER_NAME = 'Web.Offset'
        self.ADDED_PARAMS = ['&Web.Count=10']
        self.ITER_FUNC = lambda x: x * 10
        self.LOOP_POINT = lambda x: x['SearchResponse']['Web']['Results']
        self.RESULT_NODE = 'Url'

    def __retrieveLookup__(self, params):
        f = urllib2.urlopen(self.URL_PREPEND + urllib.quote(str(self.keyword)) + self.URL_APPEND + params)
        ret = self.LOOP_POINT(json.load(f))
        return ret

    def __findRank__(self):
        return [[idx + 1, i] for idx, i in enumerate(self.LOOKUP_STACK) if self.RE_OBJ.search(i)]

    def runLookup(self, flag):
        self.LOOKUP_STACK = list()
        if flag == 'y':
            self.__yahooFlag__()
        elif flag == 'g':
            self.__googleFlag__()
        elif flag == 'b':
            self.__bingFlag__()
        for i in range(0, 5):
            self.LOOKUP_STACK.extend([i[self.RESULT_NODE] for i in self.__retrieveLookup__('&' + self.ITER_NAME + '=' + str(self.ITER_FUNC(i)) + str().join(self.ADDED_PARAMS)) if i[self.RESULT_NODE]])
        return self.__findRank__()

if __name__ == '__main__':

    rankObj = RankChecker(sys.argv[1], sys.argv[2])
    print '\r\nGoogle:'
    pprint.pprint(rankObj.runLookup('g'))
    print '\r\nYahoo:'
    pprint.pprint(rankObj.runLookup('y'))
    print '\r\nBing:'
    pprint.pprint(rankObj.runLookup('b'))
PrintFriendly

Comments

No comments yet.

Leave a comment

RSS feed for comments on this post. TrackBack URL

 

©2010 Activewebsite. All Rights Reserved.