Skip to content

Commit

Permalink
[IDLE-000] 크롤링 대상 사이트에 알림창(alert)이 뜨는 케이스에 대한 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
wonjunYou committed Nov 8, 2024
1 parent d531820 commit ef1ea6b
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,6 @@ object WorknetCrawler {
errorCountMap[method] = errorCountMap.getOrDefault(method, 0) + 1
}

private fun handleAlertIfPresent() {
try {
val alert: Alert = driver.switchTo().alert()
alert.accept()
driver.navigate().back()
} catch (e: NoAlertPresentException) {
logError("handleAlertIfPresent", e)
}
}

private fun crawlPosts(
start: Int,
end: Int,
Expand All @@ -154,7 +144,10 @@ object WorknetCrawler {
val element = driver.findElement(By.xpath("//*[@id=\"list$i\"]/td[2]/a"))
element.click()

handleAlertIfPresent()
if (handleAlertIfPresent()) {
driver.navigate().back()
continue
}

val wait = WebDriverWait(driver, Duration.ofSeconds(5))
wait.until(ExpectedConditions.numberOfWindowsToBe(2))
Expand Down Expand Up @@ -190,12 +183,21 @@ object WorknetCrawler {
driver.close()
driver.switchTo().window(originalWindow)
} catch (e: Exception) {
logError("crawlPosts", e)
handleAlertIfPresent()
logError("=== 에러 원인은..", e)
}
}
}

private fun handleAlertIfPresent(): Boolean {
return try {
val alert: Alert = driver.switchTo().alert()
alert.accept() // 알림창이 있을 경우 수락
true // 알림창이 있었음을 표시
} catch (e: NoAlertPresentException) {
false // 알림창이 없었음을 표시
}
}

private fun getClientAddress(): String {
val xpaths = listOf(
"//*[@id=\"contents\"]/section/div/div[3]/div[15]/div/table/tbody/tr[4]/td/p[2]",
Expand Down

0 comments on commit ef1ea6b

Please sign in to comment.