【发布时间】:2017-09-06 15:41:06
【问题描述】:
我正在尝试从这个 html 中挖掘一些数据,
html 在另一个跨度内有跨度 (Seems like valid html according to other stack over flow post)
所以表达
td > p > span
返回 2 个元素(第二个元素包含两个 span)
有没有办法解决这个问题?
在这个例子中,我感兴趣的值是 03/26/17
<td width="414" style="width:310.25pt;border:none;border-bottom:solid #AEAAAA 1.0pt;padding:0in 5.4pt 0in 5.4pt;height:.3in">
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:normal">
<span style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black">03/</span>
<span style="font-size:8.0pt;font-family:"Arial",sans-serif">26<span style="color:black">/17</span>
</span>
<o:p/>
</p>
</td>
代码:
protected String getSimpleValue(org.jsoup.nodes.Document doc,String selector) {
StringBuffer buff = new StringBuffer();
try {
Elements result = doc.select(selector);
for (Element element : result) {
buff.append(element.ownText()+" ");
}
}catch(Exception ex) {
ex.printStackTrace();
}
return buff.toString();
}
【问题讨论】:
-
您的问题是什么?你期望什么,你会得到什么?
标签: jsoup