仅获取 id 和 href

发布于 2025-01-01 15:02:03 字数 603 浏览 3 评论 0原文

我的输出由多个 id 和 href 以及其他数据组成。

如何使用 Htmlunit 和 Java 代码获取所有 id 和 href 值?

我需要强制获取所有 href 值,但 id 不是强制的...

我该怎么做以及我应该在哪里编写给定的代码。

<a id="Repeater1_ctl00_HyperLink2" href="/jobs/Physical-Security-Specialist-308550900.html">

<a id="Repeater1_ctl05_HyperLink1" href="/jobs/Safety-and-Occup-Hlth-Specialist-308549000.html">

<a id="Repeater1_ctl08_HyperLink2" href="/jobs/Nurse-Practitioner-Oca-Esep-Dh-308526400.html">

<a id="Repeater1_ctl09_HyperLink1" href="/jobs/Nurse-Practitioner-Oca-Esep-Dh-308526400.html">

ETC.....

My output consists of multipe id and href and other data.

How to get all the id and href values using Htmlunit and Java code?

I need to get all the href values mandatory but id is not mandatory...

How can I do that and where should I write the given code.

<a id="Repeater1_ctl00_HyperLink2" href="/jobs/Physical-Security-Specialist-308550900.html">

<a id="Repeater1_ctl05_HyperLink1" href="/jobs/Safety-and-Occup-Hlth-Specialist-308549000.html">

<a id="Repeater1_ctl08_HyperLink2" href="/jobs/Nurse-Practitioner-Oca-Esep-Dh-308526400.html">

<a id="Repeater1_ctl09_HyperLink1" href="/jobs/Nurse-Practitioner-Oca-Esep-Dh-308526400.html">

etc.....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

莫多说 2025-01-08 15:02:03

我不会为您编写代码:)但我可以为您提供解决方案的想法。

获取 Html 页面。尝试获取页面的所有 HtmlAnchor 对象(您可以使用 XPath 来实现)。迭代 HtmlAnchor 集合并执行方法 getHrefAttribute() 获取 href 属性。类似地,使用 HtmlAnchor 的 getId() 方法来获取其 id。就是这样 :)

I'm not writing code for you :) But I can give you an idea of the solution.

Get the HtmlPage. Try getting all the HtmlAnchor object of the page (you can use XPath for this). Iterate over the HtmlAnchor collection and execute the method getHrefAttribute() to get the href attribute. Similary use the getId() method of the HtmlAnchor to get its id. That's it :)

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