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 个链接,有没有办法获得第二次出现?
不使用那个方法。但是您可以改为调用getAnchors()并获得一个List<HtmlAnchor>-- 如果您遍历它并调用getTextContent()每个锚点,您可以检查您想要的任何字符串并自己获取所有匹配项。
getAnchors()
List<HtmlAnchor>
getTextContent()