Htmlunit 如何创建HtmlAnchor

Htmlunit 如何创建HtmlAnchor,htmlunit,Htmlunit,我正在浏览一个网页,以获取包含特定文本的锚。我想做的是,如果没有锚满足条件,那么该方法应该返回一个新的HtmlAnchor,指向我作为参数传递的页面 public HtmlAnchor getAnchor(HtmlPage page, String criteria) { if any anchor satisfies this criteria return that anchor else create a new anchor pointing to the current

我正在浏览一个网页,以获取包含特定文本的锚。我想做的是,如果没有锚满足条件,那么该方法应该返回一个新的HtmlAnchor,指向我作为参数传递的页面

public HtmlAnchor getAnchor(HtmlPage page, String criteria)
{
   if any anchor satisfies this criteria return that anchor 
   else create a new anchor pointing to the current page and return it //how to do this
}

仅供参考:我使用的是htmlunit 2.9,看起来你不能直接实例化HtmlLanchor,但你可以创建其父对象的实例。将其“href”属性设置为该页面的url,您应该拥有所需的内容


不过,你打算怎么处理它?

我找到了一个解决方法,是的,你是对的,它不能被实例化,如果我不给出一个好的答案,那就太粗鲁了。