How to get text from element without whitespace normalization and trimmed using SwiftSoup in swift

542 Views Asked by At

I want to get exact text without whitespace normalisation and trim using SwiftSoup library.

Currently, SwiftSoup provide element.text() method to extract text from that element.

But text()- Method gives trimmed and whitespace normalised text.

Any other way to get element text without trimmed and whitespace normalised?

1

There are 1 best solutions below

0
Chaz On

This is not SwiftSoup specific but should be correct for the HTML DOM and is probably similar here:

The innerText property returns just the text, without spacing and inner element tags.
The innerHTML property returns the text, including all spacing and inner element tags.
The textContent property returns the text with spacing, but without inner element tags.

https://www.w3schools.com/jsref/prop_node_innertext.asp

Not sure how to access the textContent property with SwiftSoup (if that exists) but that's probably what you want.
In case .html() doesn't work for you.