0

How do i select the text in the span tag that excludes those unnecessary "&nbsp" characters? I need only the number (euro character at the end would be nice, but it's not a must). Note that the numbers change, they are not the same.

<span class="price">15.900&nbsp;€</span>
CsharpNoob
  • 39
  • 11

1 Answers1

1

If you use C# and XPath then assuming you write your XPath expression as a C# string you can use "translate(//span[@class = 'price'], '\u00A0', '')".

Working sample (in Javascript) is

console.log(document.evaluate("translate(//span[@class = 'price'], '\u00A0', '')", document, null, XPathResult.ANY_TYPE, null).stringValue);
<span class="price">15.900&nbsp;€</span>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Can you elaborate that /u00A0, ' ' part? – CsharpNoob Dec 18 '16 at 16:29
  • Well, see Unicode escape sequence in the documentation https://msdn.microsoft.com/en-us/library/ms228362.aspx#String%20Escape%20Sequences. And it is `\u00A0` and not `/u00A0`. – Martin Honnen Dec 18 '16 at 16:32
  • And in HTML the entity reference `nbsp;` is just the HTML way of writing the Unicode character U00A0 which Javascript or C# string literals allow you to escape as `\u00A0`. – Martin Honnen Dec 18 '16 at 16:59