Skip to content

Instantly share code, notes, and snippets.

@anthonysterling
Created December 30, 2012 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonysterling/4412671 to your computer and use it in GitHub Desktop.
Save anthonysterling/4412671 to your computer and use it in GitHub Desktop.
YQL Data Table to scrape last.fm "Top Tracks" by Tag.
<?xml version="1.0" encoding="UTF-8" ?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<description>Retrieves the Top Tracks, by tag, from Last.fm</description>
<author>Anthony Sterling</author>
</meta>
<bindings>
<select produces="JSON">
<inputs>
<key id="tag" as="tag" type="xs:string" paramType="query" required="true"/>
</inputs>
<execute><![CDATA[
var results = y.query("select content from html where url=\"http://www.last.fm/tag/" + tag + "/tracks\" and xpath='//td[@class=\"subjectCell\"]/div//a[not(contains(@href, \"download\"))]'").results.*;
var tracks = [];
var track = null;
for each (var item in results)
{
var item = item.toString();
if(null == track)
{
track = { artist: item, title: null };
continue;
}
track.title = item;
tracks.push(track);
track = null;
}
response.object = {track: tracks};
]]></execute>
</select>
</bindings>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment