From 3232a981e1825ca2e3dafe4bf7c6150dd4654ae8 Mon Sep 17 00:00:00 2001 From: Roar Date: Wed, 1 Apr 2026 13:53:57 +0200 Subject: [PATCH] Updated URLCharityScraper Added method updateKeyNumbers() that gets the value of the 3 key number values by IK for the given charity. --- .../team6/scraper/URLCharityScraper.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/URLCharityScraper.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/URLCharityScraper.java index 173785d..9b64342 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/URLCharityScraper.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/scraper/URLCharityScraper.java @@ -105,4 +105,50 @@ public boolean updateCategories() { return true; } + + public boolean updateKeyNumbers() { + WebDriver driver = new ChromeDriver(options); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + String percentage; + WebElement element; + + try { + driver.get("https://www.innsamlingskontrollen.no/organisasjoner/anna-ministries/"); + + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( + "//li[.//h2[normalize-space()='Innsamlingsprosent']]//div[@class='graph']"))); + + element = driver.findElement( + By.xpath("//li[.//h2[normalize-space()='Innsamlingsprosent']]//div[@class='graph']") + ); + + percentage = element.getAttribute("data-percentage"); + System.out.println(percentage); + + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( + "//li[.//h2[normalize-space()='Administrasjonsprosent']]//div[@class='graph']"))); + + element = driver.findElement( + By.xpath("//li[.//h2[normalize-space()='Administrasjonsprosent']]//div[@class='graph']") + ); + + percentage = element.getAttribute("data-percentage"); + System.out.println(percentage); + + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( + "//li[.//h2[normalize-space()='Formålsprosent']]//div[@class='graph']"))); + + element = driver.findElement( + By.xpath("//li[.//h2[normalize-space()='Formålsprosent']]//div[@class='graph']") + ); + + percentage = element.getAttribute("data-percentage"); + System.out.println(percentage); + + } finally { + driver.quit(); + } + + return true; + } }