Skip to content

Instantly share code, notes, and snippets.

@emirkin
Created May 15, 2012 22:57
Show Gist options
  • Save emirkin/2705804 to your computer and use it in GitHub Desktop.
Save emirkin/2705804 to your computer and use it in GitHub Desktop.
How to use Bobik in Ruby
# Demonstrates synchronous scraping using Bobik
# To make this example asynchronous, simply change `true` to `false` in calling `scrape`.
client = Bobik::Client.new(:auth_token => YOUR_AUTH_TOKEN, :timeout_ms => 60000)
sample_data = {
urls: ['amazon.com', 'zynga.com', 'http://finance.yahoo.com/'],
queries: ["//th", "//img/@src", "return document.title", "return $('script').length"]
}
client.scrape(sample_data, true) do |results, errors|
pust "Errors: #{errors}"
results.each do |url, queries|
puts "Printing results for #{url}"
queries.each do |query, result|
puts " Result of query #{query}: #{result}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment