Repository: scrapinghub/price-parser

Issue:
Bug non break space.
Some store show price with non-break space and parser return None.

Discussion:

Patch:
diff --git a/price_parser/parser.py b/price_parser/parser.py
index d1051e4..94e9e9c 100644
--- a/price_parser/parser.py
+++ b/price_parser/parser.py
@@ -188,9 +188,13 @@ def extract_price_text(price: str) -> Optional[str]:
     >>> extract_price_text("50%")
     >>> extract_price_text("50")
     '50'
+    >>> extract_price_text("$1\xa0298,00")
+    '1 298,00'
     >>> extract_price_text("$.75")
     '.75'
     """
+    price = re.sub(r'\s+', ' ', price)  # clean initial text from non-breaking and extra spaces
+
     if price.count('€') == 1:
         m = re.search(r"""
         [\d\s.,]*?\d    # number, probably with thousand separators


Test patch:
diff --git a/tests/test_price_parsing.py b/tests/test_price_parsing.py
index 8ef2b11..a6b3c52 100644
--- a/tests/test_price_parsing.py
+++ b/tests/test_price_parsing.py
@@ -429,6 +429,12 @@ PRICE_PARSING_EXAMPLES = [
             '€', '11,76', 11.76),
     Example('$99.99', '$99.99',
             '$', '99.99', 99.99),
+    Example('1\xa0298,00 €', '1\xa0298,00 €',
+            '€', '1 298,00', 1298.00),
+    Example('$1\xa0298,00', '$1\xa0298,00',
+            '$', '1 298,00', 1298.00),
+    Example('1\xa0298,00', '1\xa0298,00',
+            None, '1 298,00', 1298.00),
     Example(None, '.75 €',
             '€', '.75', 0.75),
     Example('$.75', '$.75',