Created
December 11, 2012 21:57
-
-
Save markandey/4262619 to your computer and use it in GitHub Desktop.
scrape
This file contains 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
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