Skip to content

Instantly share code, notes, and snippets.

@ismailmechbal
Created December 11, 2017 11:14
Show Gist options
  • Save ismailmechbal/918d88e7d60fc812d132e90ca3937946 to your computer and use it in GitHub Desktop.
Save ismailmechbal/918d88e7d60fc812d132e90ca3937946 to your computer and use it in GitHub Desktop.
mechanize-sidekiq
require 'mechanize'
require 'sidekiq'
class BackgroundWebCrawler < Mechanize
include Sidekiq::Worker
def perform(url)
page = get(url)
@links = page.links
while link = links.shift
page = click(link)
visit(page)
end
end
private
def visit(page)
puts page.title
@links.concat(page.links)
end
end
BackgroundWebCrawler.perform_async('http://example.com')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment