[英]How to get text between different tags in Jsoup?
I have to parse html code like this: 我必须解析这样的html代码:
<td><b>Dont need it</b>I need this!!<br><b>Dont need it too:</b> I need
this too!!<br> <b>Text:</b> I need this<br></td>
I tried something like this: 我尝试过这样的事情:
td.select("< b />< br >)") but It had trown an exception. td.select(“ <b /> <br>)”),但是它抛出了一个异常。
I am able to get the text in b tag, but how can I get text between b and br tag. 我可以在b标签中获取文本,但是如何在b和br标签之间获取文本。
You want to get all the text nodes under the <td/>
but none of the named nodes. 您想获得所有
<td/>
下的文本节点,但没有一个命名节点。 JSoup has a method called textNodes()
that returns these: JSoup有一个称为
textNodes()
的方法,该方法返回以下内容:
Element td = ...;
StringBuilder sb = new StringBuilder();
for (TextNode textNode : td.textNodes()) {
sb.append(textNode.text());
}
return sb.toString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.