YQL code samples: YQL is easy to use

YQL is easy to use. How easy? Check out these three examples:

1) Fetch Twitter search results using YQL + JSONP + a simple JavaScript handler function

Feed readers, see the code on Github.

Run this query in the YQL console:

select * from json where url="http://search.twitter.com/search.json?q=puppy"

Note: You could also use YQL’s community table for Twitter search

2) Scrape content off the World Wildlife Fund site and pass it back to a jQuery handler

Feed readers, see the code on Github.

Run the YQL query in the console:

select * from html where url=”http://www.worldwildlife.org/sites/photos/galleries.html” and
xpath=’//div[@class=”narrativeText”]/h4|//ul[@id=”speciesList”]’

Note: instead of running all this on the page, you might consider using YQL execute to generate your HTML on Yahoo! servers and pass it back to the handler for insertion into the page. You could also create an adhoc API that leans on Yahoo!'s cache to reduce WWF's bandwidth costs.

3) Convert XML to JSON in your sleep

This script instructs YQL to fetch the “UN News Centre - Top Stories” RSS feed and return it as JSON, and then drops the data on the page using YUI.

Feed readers, see the code on Github.

Run this query in the YQL console:

select * from rss where url=’http://www.un.org/apps/news/rss/rss_top.asp’

Erik Eldridge (@erikErik Eldridge)
Yahoo! Developer Network