Skip to content

Commit

Permalink
Updated URLCharityScraper
Browse files Browse the repository at this point in the history
Changed methods to return their values, and made the url a object parameter.
  • Loading branch information
roaraf committed Apr 1, 2026
1 parent bfc92ab commit ee2aee6
Showing 1 changed file with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@

public class URLCharityScraper {
ChromeOptions options;
String url;

public URLCharityScraper() {
public URLCharityScraper(String url) {
this.options = new ChromeOptions();
options.addArguments("--headless=new");
options.addArguments("--window-size=1920,1080");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
this.url = url;
}

public String updateDescription(String url) {
public String updateDescription() {
WebDriver driver = new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
StringBuilder descriptionString = new StringBuilder();

try {
driver.get(url);
driver.get(this.url);

wait.until(
ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector(".information div"), 0));
Expand All @@ -56,13 +58,13 @@ public String updateDescription(String url) {
return descriptionString.toString();
}

public boolean updateLogo() {
public String updateLogo() {
WebDriver driver = new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
String logoURL = "";
String logoURL;

try {
driver.get("https://www.innsamlingskontrollen.no/organisasjoner/anna-ministries/");
driver.get(this.url);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".logo > img")));

Expand All @@ -72,16 +74,16 @@ public boolean updateLogo() {
} finally {
driver.quit();
}
return true;
return logoURL;
}

public boolean updateCategories() {
public List<String> updateCategories() {
WebDriver driver = new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
List<String> categoriesList = new ArrayList<>();

try {
driver.get("https://www.innsamlingskontrollen.no/organisasjoner/anna-ministries/");
driver.get(this.url);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".tag-label")));

Expand All @@ -95,19 +97,18 @@ public boolean updateCategories() {
driver.quit();
}

System.out.println(categoriesList);

return true;
return categoriesList;
}

public boolean updateKeyNumbers() {
public List<String> updateKeyNumbers() {
WebDriver driver = new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
String percentage;
WebElement element;
List<String> keyNumbersList = new ArrayList<>();

try {
driver.get("https://www.innsamlingskontrollen.no/organisasjoner/anna-ministries/");
driver.get(this.url);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
"//li[.//h2[normalize-space()='Innsamlingsprosent']]//div[@class='graph']")));
Expand All @@ -117,7 +118,8 @@ public boolean updateKeyNumbers() {
);

percentage = element.getAttribute("data-percentage");
System.out.println(percentage);

keyNumbersList.add(percentage);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
"//li[.//h2[normalize-space()='Administrasjonsprosent']]//div[@class='graph']")));
Expand All @@ -127,7 +129,8 @@ public boolean updateKeyNumbers() {
);

percentage = element.getAttribute("data-percentage");
System.out.println(percentage);

keyNumbersList.add(percentage);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
"//li[.//h2[normalize-space()='Formålsprosent']]//div[@class='graph']")));
Expand All @@ -137,12 +140,13 @@ public boolean updateKeyNumbers() {
);

percentage = element.getAttribute("data-percentage");
System.out.println(percentage);

keyNumbersList.add(percentage);

} finally {
driver.quit();
}

return true;
return keyNumbersList;
}
}

0 comments on commit ee2aee6

Please sign in to comment.