Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私のページには、同じアンカー テキストを持つ 2 つのリンクがあります。
HtmlUnit を使用して、アンカー テキストでリンクを取得しています。
への呼び出し:
page.getAnchorByText("1");
常に最初のオカレンスを取得するようですが、2 つのリンクがある場合に 2 番目のオカレンスを取得する方法はありますか?
その方法を使用していません。しかし、代わりに呼び出しgetAnchors()て取得することができList<HtmlAnchor>ます -- それを反復処理してgetTextContent()各アンカーを呼び出すと、必要な文字列をチェックして、すべての一致を自分で取得できます。
getAnchors()
List<HtmlAnchor>
getTextContent()