lib/spieker/link_scraper.rb in spieker-0.0.8 vs lib/spieker/link_scraper.rb in spieker-0.0.9
- old
+ new
@@ -45,10 +45,15 @@
""
end
visit @url.path + query + "#!lang=#{@lang}"
# Capybara + selenium causes some links not to be found. There doesn't seem to be any method to that.
# Cool is tho, in JS it's a lot faster as well
- links = page.evaluate_script('document.getElementsByTagName(\'a\')').map { |el| el['href'] }
+ links = begin
+ page.evaluate_script('document.getElementsByTagName(\'a\')').map { |el| el['href'] }
+ rescue Net::ReadTimeout
+ page.all('a').map { |el| el['href'] }
+ end
+
begin
# Our javascript adds a class if the content has been succesfully submitted
page.find(:css, 'html.tolq-content-updated')
rescue Capybara::Ambiguous, Capybara::ElementNotFound => e
puts "Something went wrong with submitting the content: #{e.message}"