Created
May 18, 2012 23:02
-
-
Save emirkin/2728019 to your computer and use it in GitHub Desktop.
How to use Bobik in Javascript
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
/* | |
* Demonstrates how to scrape using different query types | |
*/ | |
var urls = ['amazon.com', 'zynga.com', 'http://finance.google.com/', 'http://shopping.yahoo.com'] | |
var queries = ["//th", "//img/@src", "return document.title", "return $('script').length", "#logo", ".logo"] | |
// Instantiate Bobik client from Bobik SDK available at http://usebobik.com/sdk. | |
// You're welcome to link directly to the JS file. However we make no guarantees about keeping the link unchanged. | |
// Thus, you should do it only when you have a quick and immediate access to where this url is used (e.g. during development) | |
var bobik = new Bobik("YOUR_AUTH_TOKEN"); | |
bobik.scrape({ | |
urls: urls, | |
queries: queries | |
}, function (scraped_data) { | |
if (!scraped_data) { | |
console.log("Data is unavailable"); | |
return; | |
} | |
var scraped_urls = Object.keys(scraped_data); | |
for (var url in scraped_urls) | |
console.log("Results from " + url + ": " + scraped_data[scraped_urls[url]]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment