summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2018-02-10 13:04:59 +0100
committerhorus2018-02-10 13:04:59 +0100
commitf870700824c9d23ccf6e8bd232ea02b44907f38c (patch)
treece32a913090c29f5d4b8131d7d973a9578408a2f
parent0dbc07daf301908e1b983fcf70a760ef8a29b898 (diff)
downloadalkobote-f870700824c9d23ccf6e8bd232ea02b44907f38c.tar.gz
Crawler extracts volume, price per litre and abv. (Whisky.de)
-rw-r--r--crawler/shop_whiskyde.go31
-rw-r--r--crawler/utility.go3
2 files changed, 19 insertions, 15 deletions
diff --git a/crawler/shop_whiskyde.go b/crawler/shop_whiskyde.go
index de55600..053cc7f 100644
--- a/crawler/shop_whiskyde.go
+++ b/crawler/shop_whiskyde.go
@@ -52,26 +52,27 @@ func ScrapeWhiskyde(shop Shop) []Angebot {
//W.Valid_until = e.ChildText(".article-price-special")
})
+ text_noisy := e.ChildText(".article-amount")
+
+ abv_noisy := strings.TrimSpace(strings.SplitAfter(text_noisy, "Liter")[1])
+ W.Volume, err = extract_volume(text_noisy)
+ if err != nil {
+ log.Fatal(err)
+ }
+ W.Abv, err = extract_abv(abv_noisy)
+ if err != nil {
+ log.Fatal(err)
+ }
+
e.ForEach(".article-amount", func(i int, e *colly.HTMLElement) {
- text_noisy := e.ChildText("span")
-
- if strings.Contains("Liter", text_noisy) {
- W.Volume, err = extract_volume(text_noisy)
- if err != nil {
- log.Fatal(err)
- }
- } else {
- W.Abv, err = extract_abv(text_noisy)
- if err != nil {
- log.Fatal(err)
- }
- }
})
if W.Volume == 0 {
- log.Println(W.Name + " kein Volume erkannt")
+ log.Println("Whisky.de: " + W.Name + " kein Volume erkannt")
+ return
}
if W.Abv == 0 {
- log.Println(W.Name + " kein Abv erkannt")
+ log.Println("Whisky.de: " + W.Name + " kein Abv erkannt")
+ return
}
W.Shop = shop.Id
diff --git a/crawler/utility.go b/crawler/utility.go
index 17ed47b..19c4050 100644
--- a/crawler/utility.go
+++ b/crawler/utility.go
@@ -67,6 +67,9 @@ func extract_abv(abv_noisy string) (float32, error) {
if strings.Contains(abv_noisy, "%") {
abv_noisy = strings.Replace(abv_noisy, "%", "", 1)
}
+ if strings.Contains(abv_noisy, "vol") {
+ abv_noisy = strings.Replace(abv_noisy, "vol", "", 1)
+ }
abv_noisy = strings.Replace(abv_noisy, ",", ".", 1)
abv_noisy = strings.TrimSpace(abv_noisy)