java – Jsoup. Parsing an element whose class starts with

Question:

There are elements like this:

<tr class="trRandom level1 color2" id="event123456" style="display: table-row;">

It happens either trRandom or trRandomChild, and in other values ​​only numbers change. How to select an element whose class begins with trRandom using the Jsoup library? You can, of course, write crutches, but I would not like it if there is a more delicate way of solving the problem.

Tried the code below, doesn't help.

select("[^trRandom]");
select("div[^trRandom]");

The rest of the methods throw exceptions. I would be grateful for any hint, thanks!

Answer:

Your code:

select("[^trRandom]");
select("div[^trRandom]");

Searches by the name of an attribute that begins with trRandom , and you need by the value of the class attribute, like this: [attr^=valPrefix] .

Вот так:

select("[class^=trRandom]");
select("div[class^=trRandom]");

More details: http://jsoup.org/apidocs/org/jsoup/select/Selector.html

Scroll to Top