tags:

views:

85

answers:

1

This YQL statement (execute in the YQL console) picks out the name and year of a film from the TMDB website.

select content from html where url="http://www.themoviedb.org/movie/27205" and xpath='//h3[@id="year"]|//h2[@id="title"]/a'

the results come back like this:

"results": {
  "a": "Inception",
  "h3": "(2010)"
}

Is there any easy way to have label the results as 'name' and 'year' rather than the html elements they were grabbed from?

Cheers!

+2  A: 

Currently there is no easy way to quickly alias the returned labels. The best way at the moment is to create a custom data table which makes your query to TMDB and transforms the result (with Javascript, in an <execute> block) to whatever you want it to be.

For example, I created a quick custom table for you which returns the results with your labels of choice (name and year). It also removes the parentheses from around the year. To give it a test run, use:

use "store://github.com/tmdb-jp" as tmdb;
select * from tmdb where movieid="27205"

With the resulting JSON having the following structure (within the usual YQL response):

"movie": {
 "title": "Inception",
 "year": "2010"
}

If you want to have a go at creating a data table yourself, or just see what's involved, then the source is on my github. Also (it might be useful) you can query for multiple movies at once:

use "store://github.com/tmdb-jp" as tmdb;
select * from tmdb where movieid in ("27205","9802")

P.S. The store:// URLs just mean that the data table is being stored in Yahoo!'s "cloud" for speed and reliability. You can of course use a normal http:// URL (e.g. by github one) instead.

salathe
You are a **hero**! A perfect answer with examples and explanations — nothing more could be asked for — thank you!
JP