Ľubomír
Ľubomír

Reputation: 1161

JSOUP generate css path and whitespace

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 ?

Upvotes: 0

Views: 80

Answers (1)

Pshemo
Pshemo

Reputation: 124225

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

Upvotes: 1

Related Questions