如何使用AND操作创建Jsoup选择器? [英] How to create an Jsoup Selector with an AND operation?

查看:135
本文介绍了如何使用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选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆