Skip to content

Commit

Permalink
Updated URLCharityScraper
Browse files Browse the repository at this point in the history
Fixed updateDescription so it doesn't output some of the text twice, and it now returns the String.
  • Loading branch information
roaraf committed Apr 1, 2026
1 parent 3232a98 commit bfc92ab
Showing 1 changed file with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,37 @@ public URLCharityScraper() {
options.addArguments("--disable-dev-shm-usage");
}

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

try {
// URL for scraping approved organizations
driver.get("https://www.innsamlingskontrollen.no/organisasjoner/anna-ministries/");
driver.get(url);

wait.until(
ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector(".information div"), 0));

// Check for if description is long and contains a "read more" link
List<WebElement> doesReadMoreExist = driver.findElements(By.cssSelector("a.read-more"));

if (!doesReadMoreExist.isEmpty()) {
WebElement descReadMore = driver.findElement(By.cssSelector("a.read-more"));
descReadMore.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".extra-info")));
}

List<WebElement> description = driver.findElements(By.cssSelector(".information div"));

for (WebElement element : description) {
descriptionString.append(element.getText());
}

// Check for if description is long and contains a "read more" link
List<WebElement> doesReadMoreExist = driver.findElements(By.cssSelector("a.read-more"));

if (!doesReadMoreExist.isEmpty()) {
WebElement descReadMore = driver.findElement(By.cssSelector("a.read-more"));
descReadMore.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".extra-info")));

List<WebElement> extraDescription = driver.findElements(By.cssSelector(".extra-info"));

for (WebElement webElement : extraDescription) {
descriptionString.append(webElement.getText());
}
}

} finally {
driver.quit();
}
return true;

return descriptionString.toString();
}

public boolean updateLogo() {
Expand Down

0 comments on commit bfc92ab

Please sign in to comment.