如何创建 HtmlAnchor

发布于 2024-12-25 08:37:47 字数 360 浏览 1 评论 0原文

我正在浏览页面以获取包含特定文本的锚点。我想要做的是,如果没有锚点满足条件,在这种情况下,该方法应该返回一个新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手长情犹 2025-01-01 08:37:47

您似乎无法直接实例化 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文