JavaScript to find your Yahoo! ranking
Motivation
Inspired by this article on SitePoint that shows how to find the Google ranking for a specific page and a search query, I decided to do the same, but for the Yahoo! ranking. The fun part is that my script is a JavaScript and requires nothing but a browser in order to run.
How mine is different
In the article above you need to use Google's SOAP service, so if you're not lucky enough to be running PHP5, you'll probably need something along the lines of PEAR SOAP or NuSOAP. That implies you also need a web server, running PHP. Then you need a Google API key and you need to download stuff and upload it to your server.
Nothing even close to that in terms of requirements if you opt in for the Yahoo! web service. All you need is a browser and JavaScript enabled, which shouldn't be a big deal, I don't think
About the Yahoo! JSON web service
Yahoo's web service can return XML as everybody else, but it can also return serialized PHP and also JSON. Using the JSON option you can make a simple XMLHTTPRequest and get all the content JavaScript-ready, without the headaches of getELementsByTagName() or other DOMmy methods to wrestle that XML tree. The problem here is that you're requesting a file from a different domain, so the browser won't allow it. Workaround - a simple PHP script to serve as a proxy. Oooor (as we said we don't need no stinkin' server) you can use the dynamic JavaScript includes (discussed here) to do the request. As a result you get a working solution with JS only.
By the way, if you're wondering about the beauty of JSON, try this eye-opener.
Demo
Ah, yes, the demo is here.
Enter a/ your URL, or part of it, and b/ a search query. Then the script will tell you where in the first 1000 results is your URL to be found. If it is found.
How it works
Check the source for the details, it's reasonably well commented, but the big picture:
- You make a request (in
yjsonrank.makeRequest()) by appending a new SCRIPT element to the HEAD of your HTML. The URL of the script element (the SRC attribute) points to the Y! web service and also passes the search query and a function to be called once the script is included. This function happens to beyjsonrank.process() - The
yjsonrank.process()function receives JSON data returned by the service, assigned to therespvariable. - We loop through
resp.ResultSet, checking everyresp.ResultSet.Resultif itsUrlproperty contains our URL. If yes - we're done! If not, we make another request this time for the next 50 results. (50 is randomly chosen, feel free to modify). We continue until we reach 1000th result, which is the max that Y! will be willing to give.
And that's pretty much it, the rest is just fluff and beautifications
More Y! info
- The JSON description
- The Web Search API page, listing all the additional parameters you can add to your search request and what format would have the result
Thanks for reading!
This entry was posted on Wednesday, April 19th, 2006 and is filed under JavaScript, JSON, yahoo. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

May 5th, 2006 at 1:37 am
[...] phpied.com It’s your responsibility to die() if necessary… – PHP Manual « JavaScript to find your Yahoo! ranking [...]
May 27th, 2006 at 5:48 pm
Aah, very nice JSON implementation, Stoyan!
/me likes!
October 26th, 2008 at 9:48 pm
That is a pretty interesting checker script you have there. I’m going to try a few of my sites just for fun. Cool…thanks a lot.
December 5th, 2010 at 2:43 pm
That is in all probability the most effective article that ever cross my reference. I don’t see why anyone ought to disagree. It could be too easy #for them# to comprehend…anyway nice work i’m coming again right here for More Nice Stuff!!
December 9th, 2010 at 9:38 pm
http://www.backlinkkazan.com
December 10th, 2010 at 8:57 pm
Value info. They must be something best. Thanks
December 12th, 2010 at 1:16 pm
Nice post. Totally agree with her.
December 23rd, 2010 at 6:22 pm
Really great info. I bookmarked it. Great work! Thanks
January 8th, 2011 at 3:27 am
I think everybody will love to examine this article again & once more and am quite sure that most visitors of this page will come here once more in future.I expect such informative articles from you.Thanks.
January 19th, 2011 at 4:19 pm
Nice article!
Thanks
August 19th, 2011 at 7:35 am
Hey there! This post could not be written any better! Reading this post reminds me of my old room mate! He always kept chatting about this. I will forward this post to him. Pretty sure he will have a good read. Thanks for sharing!