Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get cssSelector for node with escape character #222

Open
siuying opened this issue Jun 3, 2022 · 2 comments
Open

Unable to get cssSelector for node with escape character #222

siuying opened this issue Jun 3, 2022 · 2 comments

Comments

@siuying
Copy link
Contributor

siuying commented Jun 3, 2022

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()
@nikolaykargin
Copy link

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.

@siuying
Copy link
Contributor Author

siuying commented Jun 3, 2022

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\\)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants