Skip to content

Instantly share code, notes, and snippets.

@markandey
Created December 11, 2012 21:57
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 markandey/4262619 to your computer and use it in GitHub Desktop.
Save markandey/4262619 to your computer and use it in GitHub Desktop.
scrape
function getXPath(url) {
if (url.indexOf('http://www.w3schools.com/') >= 0) {
return '//div[@class="example_code notranslate"]';
}
if (url.indexOf('http://www.php.net/') >= 0 || url.indexOf('http://php.net/') >= 0) {
return '//div[@class="phpcode"]';
}
return '//pre';
}
function getResult(query) {
try {
var content = query.results.bossresponse.web.results.result[0]['abstract']['content'];
var url = query.results.bossresponse.web.results.result[0].clickurl;
var xpath = getXPath(url);
var htmlParam = {
'url': url,
'xpath': xpath
};
return y.query("select * from html where url=@url and xpath=@xpath", htmlParam);
} catch (e) {
return {
'Failed': e
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment