我是Jsoup
的新手,搜索了很长时间没有找到解决方案。
我有一个表,其中 tr
的类名末尾有空格。
<table class="table_one">
<tr class="no_background ">
<td>
<b> Text comes here</b>
</td>
<td> and here... </td>
</tr></table>
现在,我想访问文本。当我说
Select("table[class=tag_std] tr[class=bgnd_1 ]")
它返回空
列表。我如何获得值
"Text comes here and here...".
谢谢。
最佳答案
我认为你需要将标签放在标签内而不是 。
<table class="table_one">
<tr class="no_background ">
<td>
<b> Text comes here</b>
</td>
</tr>
</table>
我认为您需要这个,根据您的具体情况。这是一个简单的例子供您测试。
public static void main(String[] args) {
File input = new File("/Users/hugo/Desktop/test.html");
Document doc = null;
try {
doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
} catch (IOException e) {
e.printStackTrace();
}
Elements links = doc.select("table.table_one tr.no_background td");
for (Element element : links) {
System.out.println(element.text());
}
}
输出:
Text comes here
and here.
..
关于android - Jsoup : Select a row with class name containing whitespace at the end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14316594/