Skip to content

Instantly share code, notes, and snippets.

@captproton
Forked from cheeaun/data.html.cssselect.xml
Last active July 14, 2016 04:42
Show Gist options
  • Save captproton/1383d0fb17780498d857ac2c105b1ccc to your computer and use it in GitHub Desktop.
Save captproton/1383d0fb17780498d857ac2c105b1ccc to your computer and use it in GitHub Desktop.
Updated version of data.html.cssselect Open Data Table for YQL
<?xml version="1.0" encoding="UTF-8" ?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<sampleQuery>select * from {table} where url="www.yahoo.com" and css="#news a"</sampleQuery>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
<url></url>
</urls>
<inputs>
<key id="url" type="xs:string" paramType="variable" required="true" />
<key id="css" type="xs:string" paramType="variable" />
</inputs>
<execute><![CDATA[
//include css to xpath convert function
y.include("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/css2xpath/css2xpath.min.js");
var query = null;
if (css) {
var xpath = css2xpath(css);
y.log("xpath "+xpath);
query = y.query("select * from html where url=@url and xpath=\""+xpath+"\"",{url:url});
} else {
query = y.query("select * from html where url=@url",{url:url});
}
response.object = query.results;
]]></execute>
</select>
</bindings>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment