A versatile Ruby web spidering library that can spider a site, multiple domains, certain links or infinitely. Spidr is designed to be fast and easy to use.
A versatile Ruby web spidering library that can spider a site, multiple domains, certain links or infinitely. Spidr is designed to be fast and easy to use.
Spidr is a versatile Ruby web spidering library that can spider a site, multiple domains, certain links or infinitely. Spidr is designed to be fast and easy to use.
a tags.iframe tags.frame tags./robots.txt support.Start spidering from a URL:
Spidr.start_at('https://www.ruby-lang.org/en/') do |agent|
# ...
endSpider a host:
Spidr.host('www.ruby-lang.org') do |agent|
# ...
endSpider a domain (and any sub-domains):
Spidr.domain('ruby-lang.org') do |agent|
# ...
endSpider a site:
Spidr.site('https://www.ruby-lang.org/') do |agent|
# ...
endSpider multiple hosts:
Spidr.start_at('https://www.ruby-lang.org/en/', hosts: ['ruby-lang.org', /.*\.ruby-lang\.org\z/]) do |agent|
# ...
endDo not spider certain links:
Spidr.site('https://www.ruby-lang.org/', ignore_links: [%r{\A/blog/}]) do |agent|
# ...
endDo not spider links on certain ports:
Spidr.site('https://www.ruby-lang.org/', ignore_ports: [8000, 8010, 8080]) do |agent|
# ...
endDo not spider links blacklisted in robots.txt:
Spidr.site('https://www.ruby-lang.org/', robots: true) do |agent|
# ...
endPrint out visited URLs:
Spidr.site('https://www.ruby-lang.org/') do |spider|
spider.every_url { |url| puts url }
endBuild a URL map of a site:
url_map = Hash.new { |hash,key| hash[key] = [] }
Spidr.site('https://www.ruby-lang.org/') do |spider|
spider.every_link do |origin,dest|
url_map[dest] >> #{page.url}"
page.search('//meta').each do |meta|
name = (meta.attributes['name'] || meta.attributes['http-equiv'])
value = meta.attributes['content']
puts " #{name} = #{value}"
end
end
endPrint out the titles from every page:
Spidr.site('https://www.ruby-lang.org/') do |spider|
spider.every_html_page do |page|
puts page.title
end
endPrint out every HTTP redirect:
Spidr.host('www.ruby-lang.org') do |spider|
spider.every_redirect_page do |page|
puts "#{page.url} -> #{page.headers['Location']}"
end
endFind what kinds of web servers a host is using, by accessing the headers:
servers = Set[]
Spidr.host('www.ruby-lang.org') do |spider|
spider.all_headers do |headers|
servers 1000 }
spider.skip_link!
end
end
end$ gem install spidrSee {file:LICENSE.txt} for license information.
No open issues yet, or sync has not completed.