From 3eea0c0146ae1c94cfaccba35d9240c349acd6bf Mon Sep 17 00:00:00 2001 From: Emirhan Akdeniz <73674035+kagermanov27@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:14:43 +0300 Subject: [PATCH] Update cached link handling - Check if there are any cached links on SerpApi Response - Recreate cached links if there aren't any cached links --- lib/clauneck.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/clauneck.rb b/lib/clauneck.rb index e61173f..6f25c2e 100644 --- a/lib/clauneck.rb +++ b/lib/clauneck.rb @@ -312,7 +312,13 @@ def parse_pages(pages) if !pages.empty? && pages != nil pages.flat_map do |page| if page - page['organic_results']&.map { |r| r.dig('cached_page_link') } + cached_links = page['organic_results']&.map { |r| r.dig('cached_page_link') } + direct_links = page['organic_results']&.map { |r| r.dig('link') } + if !cached_links&.compact.empty? + cached_links + else + direct_links&.map {|r| "http://webcache.googleusercontent.com/search?q=cache:#{r}"} + end else puts <<-HELP Warning: There's a problem connecting to SerpApi. Make sure you have used the correct API Key.