From 39427e21fc61ef62b139c792ee5c456f0f1c4dde Mon Sep 17 00:00:00 2001 From: lantzelot-swe <75668734+lantzelot-swe@users.noreply.github.com> Date: Tue, 9 Jan 2024 10:37:52 +0100 Subject: [PATCH] fix: nullpointer when scraping musician from Moby games in some situations --- .../java/se/lantz/scraper/MobyGamesScraper.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/se/lantz/scraper/MobyGamesScraper.java b/src/main/java/se/lantz/scraper/MobyGamesScraper.java index 0da1ace..abe7641 100644 --- a/src/main/java/se/lantz/scraper/MobyGamesScraper.java +++ b/src/main/java/se/lantz/scraper/MobyGamesScraper.java @@ -314,8 +314,17 @@ public class MobyGamesScraper implements Scraper { Element musicElement = musicElements.get(0); Element musicParent = musicElement.parent(); - - value = musicParent.getElementsByTag("a").first().text(); + if (musicParent.getElementsByTag("a").first() != null) + { + value = musicParent.getElementsByTag("a").first().text(); + } + else + { + Element commaListElement = musicParent.getElementsByClass("commaList").first(); + final List musicList = new ArrayList<>(); + commaListElement.getElementsByTag("li").forEach(liElement -> musicList.add(liElement.text())); + value = String.join(",", musicList); + } } } } @@ -323,7 +332,6 @@ public class MobyGamesScraper implements Scraper { ExceptionHandler.handleException(e, "Could not scrape composer"); } - return value; }