Jump to content

Yahoo Query Language

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 202.46.23.55 (talk) at 08:27, 23 September 2010 (YQL Page Scraping). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Yahoo! query language (YQL) is an SQL-like query language created by Yahoo! as part of their Developer Network. YQL is designed to retrieve and manipulate data from APIs through a single Web interface, thus allowing mashups that enable developers to create their own applications.[1]

Initially launched in October 2008 with access to Yahoo APIs,[2] February 2009 saw the addition of open data tables from third parties such as Google Reader, the Guardian, and The New York Times.[3] Some of these APIs still require an API key to access them. On April 29th of 2009, Yahoo introduced the capability to execute the tables of data built through YQL using JavaScript run on the company's servers for free.[3]

YQL Page Scraping

One of the most common use of YQL is getting data from any page on the internet(page scraping), thats why some of the people say yql can do

"Select * from internet"

For example to get data from this page you can do some thing like this


select * from html where url="http://en.wikipedia.org/wiki/Yahoo!_query_language" and
      xpath='//div[@id="bodyContent"]'

All data from YQL can be consumed in form of JSON or XML Here is sample html and JavaScript Code which is using YQL Rest API

<HTML> 
<HEAD> 
<TITLE>YQL DEMO</TITLE> 
<STYLE type="text/css"> 
 body{text-align: center;background:#c0c0c0;}
 #mycontent{margin-left: auto;margin-right: auto;width: 780px;font-size:80%;background:#ffffff; border: 1em solid #fff;}
 </STYLE> 
<SCRIPT type="text/javascript">
function ren(o) {
    var d = document.getElementById("main");
    var h = "";
    var i;
    var c;
    if (d) {
        if (o.results[0]) {
            c = o.results.length;
            for (i = 0; i < c; i++) {
                h = h + o.results[i] + '><br/' + '>';
            }
            d.innerHTML = h;
        } else if (o.results) {
            d.innerHTML = o.results;
        } else {
            d.innerHTML = 'failed';
        }
    }
}
</SCRIPT> 
</HEAD> 
<BODY> 
<DIV id="mycontent"> 
    <H1 id="titletext">Yahoo! query language - Wikipedia, the free encyclopedia</H1> 
    <HR> 
    <DIV id="main"> 
      Loading YQL JSON...
    </DIV> 
	</DIV> 
<script src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A//en.wikipedia.org/wiki/Yahoo%21_query_language%22%20and%0A%20%20%20%20%20%20xpath%3D'//div%5B@id%3D%22bodyContent%22%5D/p%5B1%5D'&format=xml&diagnostics=true&callback=ren">
</script>	
</BODY> 
</HTML> 
 
 

One the example page where this data is scrapped is here

References

  1. ^ Perez, Juan Carlos (April 29, 2009). "Yahoo Extends YQL Web Data Query Platform". PC World.
  2. ^ Kolakowski, Nicholas (April 29, 2009). "Yahoo Launches YQL Execute, Updates YSlow". eWeek.
  3. ^ a b O'Dell, Jolie (May 2, 2009). "Developers: Never Mind the APIs, Here's YQL Execute". ReadWriteWeb.