Created
December 11, 2017 11:14
-
-
Save ismailmechbal/918d88e7d60fc812d132e90ca3937946 to your computer and use it in GitHub Desktop.
mechanize-sidekiq
This file contains hidden or 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
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