Rectangle 27 0

java retrieve html inline style attribute value with jsoup?


<th style="text-align:right">4389</th>
text-align:right
right
final String html = "<th style=\"text-align:right\">4389</th>";

Document doc = Jsoup.parse(html, "", Parser.xmlParser()); // Using the default html parser may remove the style attribute
Element th = doc.select("th[style]").first();


String style = th.attr("style"); // You can put those two lines into one
String styleValue = style.split(":")[1]; // TODO: Insert a check if a value is set

// Output the results
System.out.println(th);
System.out.println(style);
System.out.println(styleValue);

You can retrieve the style attribute of the element and then split it by :.

this is the solution i had finally imagined but in a different way. Thank you @wartai for your help.

Note