From b4d37fbc3fd57196713ddf1c72c053ccc821edf2 Mon Sep 17 00:00:00 2001 From: akaessens <24660231+akaessens@users.noreply.github.com> Date: Tue, 10 Aug 2021 14:25:43 +0200 Subject: [PATCH] Correctly exit if error in scraping instead of endless loop --- .../java/com/akdev/nofbeventscraper/DocumentReceiver.java | 4 ++-- .../main/java/com/akdev/nofbeventscraper/FbPageScraper.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/akdev/nofbeventscraper/DocumentReceiver.java b/app/src/main/java/com/akdev/nofbeventscraper/DocumentReceiver.java index 8707e2a..a38b2e5 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/DocumentReceiver.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/DocumentReceiver.java @@ -19,7 +19,7 @@ public class DocumentReceiver { // use default android user agent String user_agent = "Mozilla/5.0 (X11; Linux x86_64)"; - Log.d("scraperLog", "DocumentReceiver: "+url); + Log.d("scraperLog", "DocumentReceiver: " + url); Connection connection = Jsoup.connect(url).userAgent(user_agent).followRedirects(true); @@ -27,7 +27,7 @@ public class DocumentReceiver { document = response.parse(); - Log.d("scraperLog", "Document title: "+document.title()); + Log.d("scraperLog", "Document title: " + document.title()); try { // accept cookies needed? diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbPageScraper.java b/app/src/main/java/com/akdev/nofbeventscraper/FbPageScraper.java index b026deb..389f516 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/FbPageScraper.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbPageScraper.java @@ -99,9 +99,11 @@ public class FbPageScraper extends AsyncTask { } catch (IOException e) { e.printStackTrace(); this.error = R.string.error_connection; + return null; } catch (Exception e) { e.printStackTrace(); this.error = R.string.error_unknown; + return null; } } while (url != null);