1

私はこのようなテーブルを持っています:

    <table class=firstclass>
   <tr>
      <td><a href....></a></td>
   </tr>
    <tr>
       <td><a href....></a></td>
    </tr>
    <tr>
      <td><a href....></a></td>
    </tr>

このページには他のテーブルがあるので、次のようなものを使用する必要があると思います。

  doc.select("td.firstclass > a[href]");

しかし、それは機能しません。

私はこれで解決しました:

       Element table = doc.select("table.firstclass").first(); //gets a table with the class                 "first class"
        Elements links = table.select("a[href]");
        for (Element link : links) {

            String textlink= link.text();
             String urllink= link.attr("abs:href");
            ));  

        }
// ...
4

1 に答える 1

1

「td.firstclass」を使用すると、TD がクラス「firstclass」を持つことを意味します。これが、結果が 0 になる理由です。

あなたは次のようなことをする必要があります..

Document doc = ....; //however you get your document

Element table = doc.select("table.firstclass").first(); //gets a table with the class "first class"
Elements links = table.select("a[href]");

そこから、必要に応じてリンクを処理できます

于 2013-01-10T17:49:02.030 に答える