2

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.

  • Must you *only* select it with whitespace at the end? If you just want the `tr` with that class regardless of whitespace just use `tr.no_background`. – BoltClock Jan 14 '13 at 13:03
  • @BoltClock hi, yes. I need the whitespace. If is say tr.no_background I get an empty list as "no_background" doesnt match "no_background " (with ending whitespace) – Manikandan Kandasamy Jan 14 '13 at 13:53

1 Answers1

2

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.

..

Hao Liu
  • 122
  • 3