简体   繁体   English

如何使用 AND 操作创建 Jsoup 选择器?

[英]How to create an Jsoup Selector with an AND operation?

I want to find the following tag in a html.我想在 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] .我知道我可以使用 a [href^=http://www.google.com/]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!谢谢!

Just combine them in a single CSS selector.只需将它们组合在一个 CSS 选择器中即可。

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.对于这样一个世界级的 HTML 解析器,考虑正则表达式是没有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM