2012-02-13 6 views
0

私は親のdivページと複数の子Divタグを持っています。私は親div内の子divの数を数えたいと思います。 JSoupで可能ですか?以下は、最も説明するためのコードです。親タグ内に子タグを数えよう

<div class="pagination"> 
<div class="label">Page: </div> 
<div class="button selected" onclick="$('.page-position', $(this).closest('form')).attr('value', $(this).html()); $(this).closest('form').submit();">1</div> 
<div class="button " onclick="$('.page-position', $(this).closest('form')).attr('value', $(this).html()); $(this).closest('form').submit();">2</div> 
<div class="button " onclick="$('.page-position', $(this).closest('form')).attr('value', $(this).html()); $(this).closest('form').submit();">3</div> 
<div class="button" onclick="$('.page-position', $(this).closest('form')).attr('value', 2);$(this).closest('form').submit();">Next</div> 
</div> 

[次へ]ボタンを除いた合計ページ数をカウントします。次に、選択し

Document doc = Jsoup.connect("http://url").get(); 

答えて

3

がJsoupあたりの文書を入手

Elements els = doc.select("div.pagination div").not(":contains(Next)").not(":contains(Page)"); 

または正規表現を介した:

els.size(); 

Elements els = doc.select("div.pagination div:matches(\\d+)"); 

は、サイズを取得します。

-2

私はjQueryを使ってそれを行うだろう:

Document doc = Jsoup.parse(input); 

または:

alert ($('.pagination div').not($("div:contains('Next')")).length); 
関連する問題