@@ -15,37 +15,33 @@ type ScraperImpl struct {
15
15
Collector * colly.Collector
16
16
}
17
17
18
- // CleanPrice implements Scraper.
19
18
// CleanPrice implements Scraper.
20
19
func (s * ScraperImpl ) CleanPrice (price string ) ([]int , error ) {
21
20
cleaned := strings .ReplaceAll (price , "$" , "" )
22
21
cleaned = strings .ReplaceAll (cleaned , "." , "" )
23
- cleaned = strings .TrimSpace (cleaned ) // Limpieza adicional
22
+ cleaned = strings .TrimSpace (cleaned )
24
23
25
- if strings .Contains (cleaned , "\u2013 " ) {
26
- priceParts := strings .Split (cleaned , "\u2013 " )
24
+ if strings .Contains (cleaned , "– " ) {
25
+ priceParts := strings .Split (cleaned , "– " )
27
26
var prices []int
28
27
for _ , part := range priceParts {
29
28
part = strings .TrimSpace (part )
30
- if part == "" {
31
- logrus .WithError (errors .New ("empty price part" )).Error ("empty price part" )
32
- return nil , errors .New ("empty price part" )
33
- }
34
29
price , err := strconv .Atoi (part )
35
30
if err != nil {
36
- logrus .WithError (err ).Error ("error converting price to int" )
37
- return nil , errors . New ( "error converting price to int" )
31
+ logrus .WithError (err ).Errorf ("error converting price to int: %s" , part )
32
+ continue // Skip this part instead of returning an error
38
33
}
39
-
40
34
prices = append (prices , price )
41
35
}
42
-
36
+ if len (prices ) == 0 {
37
+ return nil , errors .New ("no valid prices found" )
38
+ }
43
39
return prices , nil
44
40
}
45
41
46
42
priceInt , err := strconv .Atoi (cleaned )
47
43
if err != nil {
48
- logrus .WithError (err ).Error ("error converting price to int" )
44
+ logrus .WithError (err ).Errorf ("error converting price to int: %s" , cleaned )
49
45
return nil , errors .New ("error converting price to int" )
50
46
}
51
47
0 commit comments