Created
December 30, 2012 12:52
-
-
Save anthonysterling/4412671 to your computer and use it in GitHub Desktop.
YQL Data Table to scrape last.fm "Top Tracks" by Tag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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