Created
June 15, 2012 08:42
-
-
Save thesp0nge/2935464 to your computer and use it in GitHub Desktop.
This gist is just for demo purpose for a talk I gave at Italian RubyDay in Milan, June 15 2012
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
| *.swp |
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
| #!/usr/bin/env ruby | |
| require 'anemone' | |
| require 'httpclient' | |
| require 'getoptlong' | |
| # Yes, I was buit just for RubyDay 2012 talk demo | |
| # https://gist.github.com/2935464 | |
| module RubyDayIt | |
| module Crawling | |
| class Demo | |
| def self.test_1(url) | |
| Anemone.crawl(url) do |anemone| | |
| anemone.on_every_page do |page| | |
| puts page.url | |
| end | |
| end | |
| end | |
| def self.test_2(url) | |
| h=HTTPClient.new() | |
| Anemone.crawl(url) do |anemone| | |
| anemone.on_every_page do |page| | |
| response = h.get(page.url) | |
| puts "Original: #{page.url}: #{response.code}" | |
| response = h.get(page.url.to_s.split(";")[0].concat(".bak")) | |
| puts "BAK: #{page.url.to_s.split(";")[0].concat(".bak")}: #{response.code}" | |
| response = h.get(page.url.to_s.split(";")[0].concat(".old")) | |
| puts "OLD: #{page.url.to_s.split(";")[0].concat(".old")}: #{response.code}" | |
| response = h.get(page.url.to_s.split(";")[0].concat("~")) | |
| puts "~: #{page.url.to_s.split(";")[0].concat("~")}: #{response.code}" | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| opts = GetoptLong.new( | |
| [ '--test-1', '-1', GetoptLong::NO_ARGUMENT ], | |
| [ '--test-2', '-2', GetoptLong::NO_ARGUMENT ] | |
| ) | |
| opts.each do |opt, arg| | |
| case opt | |
| when '--test-1' | |
| RubyDayIt::Crawling::Demo.test_1(ARGV[0]) | |
| when '--test-2' | |
| RubyDayIt::Crawling::Demo.test_2(ARGV[0]) | |
| end | |
| end | |
| # http://localhost:8080/HacmeBooks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment