Skip to content

Commit

Permalink
Updated URLCharityScraper
Browse files Browse the repository at this point in the history
Added method to get the URL of the logo. Converted WebDriverWait object to an object parameter, and initialize it in the constructor.
  • Loading branch information
roaraf committed Apr 7, 2026
1 parent 3cf7984 commit d2f0a54
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class URLCharityScraper {
ChromeOptions options;
WebDriver driver;
WebDriverWait wait;

public URLCharityScraper() {
this.options = new ChromeOptions();
Expand All @@ -23,6 +24,8 @@ public URLCharityScraper() {
options.addArguments("--disable-dev-shm-usage");

this.driver = new ChromeDriver(options);

this.wait = new WebDriverWait(driver, Duration.ofSeconds(30));
}

public boolean updateDescription() {
Expand All @@ -32,8 +35,7 @@ public boolean updateDescription() {
// URL for scraping approved organizations
driver.get("https://www.innsamlingskontrollen.no/organisasjoner/anna-ministries/");

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(
this.wait.until(
ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector(".information div"), 0));

List<WebElement> description = driver.findElements(By.cssSelector(".information div"));
Expand All @@ -48,7 +50,7 @@ public boolean updateDescription() {
if (!doesReadMoreExist.isEmpty()) {
WebElement descReadMore = driver.findElement(By.cssSelector("a.read-more"));
descReadMore.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".extra-info")));
this.wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".extra-info")));

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

Expand All @@ -62,4 +64,21 @@ public boolean updateDescription() {
}
return true;
}

public boolean updateLogo() {
String logoURL = "";

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

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

WebElement logo = driver.findElement(By.cssSelector(".logo > img"));

logoURL = logo.getAttribute("src");
} finally {
driver.close();
}
return true;
}
}

0 comments on commit d2f0a54

Please sign in to comment.