File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
src/main/kotlin/com/stefanbratanov/sofiasupermarketsapi Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -54,10 +54,9 @@ class FantasticoBrochureDownloader(@Value("\${fantastico.url}") private val url:
54
54
val htmlDoc = getHtmlDocument(url)
55
55
56
56
val driver = ChromeDriver (options)
57
-
58
57
val waitDriver = WebDriverWait (driver, Duration .ofSeconds(30 ))
59
58
60
- val brochures =
59
+ return try {
61
60
htmlDoc
62
61
.select(" div.brochure-container.first div.hold-options" )
63
62
.filter {
@@ -81,6 +80,7 @@ class FantasticoBrochureDownloader(@Value("\${fantastico.url}") private val url:
81
80
82
81
// loading the flipping book
83
82
for (attempt in 1 .. 3 ) try {
83
+ log.info(" Loading flipping book from {}" , flippingBookUrl)
84
84
driver.get(flippingBookUrl)
85
85
break
86
86
} catch (_: TimeoutException ) {
@@ -110,10 +110,9 @@ class FantasticoBrochureDownloader(@Value("\${fantastico.url}") private val url:
110
110
111
111
Brochure (downloadPath, dateRange?.first, dateRange?.second)
112
112
}
113
-
114
- driver.quit()
115
-
116
- return brochures
113
+ } finally {
114
+ driver.quit()
115
+ }
117
116
}
118
117
119
118
private fun extractDateRange (description : String? ): Pair <LocalDate ?, LocalDate ?>? {
Original file line number Diff line number Diff line change @@ -12,14 +12,21 @@ import org.springframework.stereotype.Component
12
12
@Component
13
13
class LidlSublinksScraper (@Value(" \$ {lidl.base.url}" ) private val baseUrl : URL ) : SublinksScraper {
14
14
15
+ private val sublinksToAccept =
16
+ listOf (" niska-tsena-visoko-kachestvo" .toRegex(), " lidl-plus" .toRegex())
17
+
15
18
override fun getSublinks (): List <URL > {
16
19
log.info(" Scraping {} for sublinks" , baseUrl)
17
20
18
21
return getHtmlDocument(baseUrl)
19
22
.select(" li.AHeroStageItems__Item > a" )
20
- .map {
23
+ .mapNotNull {
21
24
val href = it.attr(" href" )
22
- baseUrl.toURI().resolve(href).toURL()
25
+ if (sublinksToAccept.none { rgx -> href.contains(rgx) }) {
26
+ null
27
+ } else {
28
+ baseUrl.toURI().resolve(href).toURL()
29
+ }
23
30
}
24
31
.distinct()
25
32
}
You can’t perform that action at this time.
0 commit comments