2

私は初心者で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 ]")

リストを返しemptyます。値を取得するにはどうすればよいですか

"Text comes here and here...".

ありがとう。

4

1 に答える 1

2

の代わりにタグをタグの中に入れる必要があると思います。

<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.

..

于 2013-01-14T10:36:25.687 に答える