android - Jsoup : Select a row with class name containing whitespace at the end

标签 android css-selectors whitespace jsoup

我是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/

相关文章:

android - Crashlytics 织物 : Failed to execute task

android - onTextChanged 不起作用

java - android.view.InflateException : Binary XML file line #29: Error inflating class android. widget.Button

java - 如何单击带有文本的元素作为编辑?

带正则表达式的 CSS2 属性选择器

php - 从 HTML 中删除空格

Java 或 Eclipse 上的空格为 'fails'(?)

java - org.XML.sax.SAXParseException : Unexpected token (position:TEXT @1:2 in java. io.StringReader@959e0aa)

xpath - Jsoup css 选择器代码(包含 xpath 代码)

Ruby:将字符串转换为 UTF-8 后删除不可见字符