SwiftSoup
SwiftSoup copied to clipboard
Unable to get cssSelector for node with escape character
When there were non alphanumeric characters in css classes, cssSelector()
will failed with error like "Could not parse query div.Fz(xs).Fw(b): unexpected token at (xs).Fw(b)"
Sample:
let html: String = #"<div class="Fz(xs) Fw(b)"><div>149.64</div></div>"#
let doc = try SwiftSoup.parse(html)
let element = try doc.getElementsContainingOwnText("149.64")
try element.first()?.cssSelector()
What result do you expect?
As I know, parentheses are reserved in CSS. Safari also can't get an accurate CSS selector for this example.
I'd expect they are escaped as described in CSS.escape() or escape a character
As an example, in this page, i can get the selector fin-streamer.Fw\(b\):nth-child(1) > span:nth-child(1)
from Firefox. You can try it on the page with selector (note the escape) document.querySelector(".Fw\\(b\\)")