如何创建 HtmlAnchor
我正在浏览页面以获取包含特定文本的锚点。我想要做的是,如果没有锚点满足条件,在这种情况下,该方法应该返回一个新的 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
I am surfing a page to get anchors containing a particular text. What I want to do is if no anchor satifies the criteria in that case the method should return a new HtmlAnchor pointing to the page I passed as a parameter.
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
}
FYI : I am using htmlunit 2.9
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎无法直接实例化
HtmlAnchor
,但您可以创建其父级的实例,HtmlElement。将其“href”属性设置为该页面的 url,您应该会得到您想要的内容。不过,你打算用它做什么呢?
It doesn't appear you can instantiate an
HtmlAnchor
directly, but you can create an instance of its parent, HtmlElement. Set its "href" attribute to the url of that page, and you should have what you want.What do you intend to do with it, though?