From 2778252c22e00fd4f92cb77769edf424cc55667b Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Tue, 25 Sep 2018 14:13:21 +0100 Subject: [PATCH] Raise exception if search gives "too many results" error. Fix #14 --- lib/uk_planning_scraper.rb | 3 +++ lib/uk_planning_scraper/idox.rb | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/uk_planning_scraper.rb b/lib/uk_planning_scraper.rb index d011469..151390a 100644 --- a/lib/uk_planning_scraper.rb +++ b/lib/uk_planning_scraper.rb @@ -10,4 +10,7 @@ module UKPlanningScraper class AuthorityNotFound < StandardError end + + class TooManySearchResults < StandardError + end end diff --git a/lib/uk_planning_scraper/idox.rb b/lib/uk_planning_scraper/idox.rb index f17d291..84760d1 100644 --- a/lib/uk_planning_scraper/idox.rb +++ b/lib/uk_planning_scraper/idox.rb @@ -51,6 +51,10 @@ module UKPlanningScraper page = form.submit + if page.search('.errors').inner_text.match(/Too many results found/i) + raise TooManySearchResults.new("Scrape in smaller chunks. Use shorter date ranges and/or more search parameters.") + end + loop do # Parse search results items = page.search('li.searchresult')