How to create an Jsoup Selector with an AND operation?

久未见 提交于 2020-01-02 05:50:04

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/7577642/how-to-create-an-jsoup-selector-with-an-and-operation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!