Skip to content

Commit

Permalink
Merge 4d2030c into 69a8ea8
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Mar 30, 2019
2 parents 69a8ea8 + 4d2030c commit 700cc82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/miteru/crawler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def execute
website = Website.new(url)
downloader.download_kits(website.kits) if website.has_kits? && auto_download?
notify(website) if verbose || website.has_kits?
rescue OpenSSL::SSL::SSLError, HTTP::Error, LL::ParserError, Addressable::URI::InvalidURIError => _
rescue OpenSSL::SSL::SSLError, HTTP::Error, Addressable::URI::InvalidURIError => _
next
end
end
Expand Down
21 changes: 16 additions & 5 deletions lib/miteru/website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ def initialize(url)
end

def title
doc.at_css("title")&.text
doc&.at_css("title")&.text
end

def kits
@kits ||= doc.css("a").map do |a|
link = a.get("href")
@kits ||= links.map do |link|
kit = Kit.new(base_url: url, link: link.to_s)
kit.valid? ? kit : nil
end.compact
Expand All @@ -35,7 +34,7 @@ def kits?

def has_kits?
ok? && index? && kits?
rescue OpenSSL::SSL::SSLError, HTTP::Error, LL::ParserError, Addressable::URI::InvalidURIError => _
rescue OpenSSL::SSL::SSLError, HTTP::Error, Addressable::URI::InvalidURIError => _
false
end

Expand All @@ -55,7 +54,19 @@ def get
end

def doc
@doc ||= Oga.parse_html(response.body.to_s)
@doc ||= [].tap do |out|
out << Oga.parse_html(response.body.to_s)
rescue LL::ParserError => _
out << nil
end.first
end

def links
if doc
doc.css("a").map { |a| a.get("href") }.compact
else
[]
end
end
end
end

0 comments on commit 700cc82

Please sign in to comment.