Added ignore option to cli

This commit is contained in:
Chris Watson 2019-07-01 09:55:07 -07:00
parent 19e022faae
commit 18eb31c0ce
No known key found for this signature in database
GPG Key ID: 37DAEF5F446370A4
3 changed files with 27 additions and 13 deletions

View File

@ -39,6 +39,7 @@ module Arachnid
that responded with that code"
option "-n", "--limit NUM", type: Int32, desc: "maximum number of pages to scan"
option "-f", "--fibers NUM", type: Int32, desc: "maximum amount of fibers to spin up", default: 10
option "-i", "--ignore PATTERNS", type: Array(String), desc: "url patterns to ignore (regex)"
option "-o FILE", "--output=FILE", type: String, desc: "file to write the report to (if undefined \
output will be printed to STDOUT"
@ -75,6 +76,7 @@ module Arachnid
option "-o FILE", "--output=FILE", type: String, desc: "filename to write the report to. \
default is the hostname + .json or .xml"
option "-f", "--fibers NUM", type: Int32, desc: "maximum amount of fibers to spin up", default: 10
option "-i", "--ignore PATTERNS", type: Array(String), desc: "url patterns to ignore (regex)"
run do |opts, args|
if args.size != 1

View File

@ -18,6 +18,12 @@ module Arachnid
spider = Arachnid::Agent.new(fibers: opts.fibers)
spider.visit_urls_like(Regex.new(Regex.escape(url.to_s)))
opts.ignore.each do |pattern|
pattern = Regex.new(pattern)
pp pattern
spider.ignore_urls_like(pattern)
end
map = {
domain: url.to_s,
lastmod: {

View File

@ -15,6 +15,12 @@ module Arachnid
spider.visit_urls_like(Regex.new(url))
end
opts.ignore.each do |pattern|
pattern = Regex.new(pattern)
pp pattern
spider.ignore_urls_like(pattern)
end
pages = 0
internal_links = Hash(String, Array(String)).new
external_links = Hash(String, Array(String)).new