如何使用 AND 运算创建 Jsoup 选择器?

发布于 2024-12-06 14:35:40 字数 288 浏览 3 评论 0原文

我想在 html 中找到以下标签。

<a href="http://www.google.com/AAA" class="link">AAA</a>

我知道我可以使用 a[href^=http://www.google.com/]a[class=link] 这样的选择器。 但我怎样才能将这两个条件结合起来呢?

或者有更好的方法来做到这一点吗?像正则表达式一样?又如何呢? 谢谢!

I want to find the following tag in a html.

<a href="http://www.google.com/AAA" class="link">AAA</a>

I know I can use a selector like a[href^=http://www.google.com/] or a[class=link].
But how can I combine this two conditions?

Or is there a better way to do this? Like regex? and how?
Thanks!

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

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

发布评论

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

评论(1

够钟 2024-12-13 14:35:40

只需将它们组合到一个 CSS 选择器中即可。

Elements links = document.select("a[href^=http://www.google.com/][class=link]");
// ...

或者

Elements links = document.select("a.link[href^=http://www.google.com/]");
// ...

考虑正则表达式对于这样一个世界级的 HTML 解析器来说是没有意义的。

Just combine them in a single CSS selector.

Elements links = document.select("a[href^=http://www.google.com/][class=link]");
// ...

or

Elements links = document.select("a.link[href^=http://www.google.com/]");
// ...

Considering regex makes no sense with such a world class HTML parser.

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