Manikandan Kandasamy
Manikandan Kandasamy

Reputation: 126

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

I am a newbie in Jsoup and could not find a solution while searching for a long time. I have a table, in which the tr has a classname with whitespace at the end.

<table class="table_one">
<tr class="no_background ">
<td>
<b> Text comes here</b>
</td>
<td> and here... </td>
</tr></table>

Now, I want to access the text. When I say

Select("table[class=tag_std] tr[class=bgnd_1 ]")

it returns empty list. How do I get the value as

"Text comes here and here...".

Thanks.

Upvotes: 2

Views: 2577

Answers (1)

Hao Liu
Hao Liu

Reputation: 122

I think you need to put your tag inside a tag instead of .

<table class="table_one">
<tr class="no_background ">
    <td>
        <b> Text comes here</b>
    </td>
</tr>
</table>

And I think you need this, according to your exact situation. Here is a simple example for you to test.

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());
    }
}

Output:

Text comes here
and here.

..

Upvotes: 2

Related Questions