0

I am trying to get css path of element from JSOUP document. This elemnt looks like this:

<div class="column" id="
                        datagrid147">
          <div>
            //Other data
          </div>
</div>

Problem is whitespace in ID, when I get css selector from JSOUP element, it contains whitespace therefore is incorrect and when I remove whitespace, selector will not work for that element. So how to get correct css selector for element defined like this in JSOUP ?

1 Answer 1

1

Proper solution would most likely involve cleaning attributes first (maybe with trim() method), then selecting elements.

But way around could be using [attr~=regex] selector, which in your case could look like div[id~=^\\s+datagrid147$].

Another way could be using [attr$=value] where attribute attr ends with specified value like div[id$=datagrid147]

More help about selectors at: https://jsoup.org/cookbook/extracting-data/selector-syntax

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I used regex solution and it is working like it should.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.