本文介绍了如何使用AND操作创建Jsoup选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在html中找到以下标记。
I want to find the following tag in a html.
<a href="http://www.google.com/AAA" class="link">AAA</a>
我知道我可以使用像一样的选择器[href ^ = http:// www .google.com /] 或 a [class = link] 。
但是我如何结合这两个条件?
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!
推荐答案
只需将它们组合在一个CSS选择器中。
Just combine them in a single CSS selector.
Elements links = document.select("a[href^=http://www.google.com/][class=link]");
// ...
或
Elements links = document.select("a.link[href^=http://www.google.com/]");
// ...
考虑到使用这样一个世界级的HTML解析器,正则表达式毫无意义。
Considering regex makes no sense with such a world class HTML parser.
这篇关于如何使用AND操作创建Jsoup选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!