有人帮我用 jsoup 检索这个例子中文本对齐样式的值吗?
<th style="text-align:right">4389</th>
这里我想获取正确的值
谢谢!
最佳答案
你可以获取元素的style
属性,然后通过:
拆分。
示例:
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);
输出:
<th style="text-align:right">4389</th>
text-align:right
right
关于java - 使用 jsoup 检索 html 内联样式属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17108310/