繁体   English   中英

在Jsoup中,如何通过属性而不是数据来解析CSS查询?

[英]In Jsoup, how do I parse the CSS query by the attribute, instead of the data?

在Jsoup中,当我使用CSS Query option解析URL http://www.singaporepools.com.sg/Lottery?page=wc_four_d时,我为第一个元素获得了“选择绘制日期” ,并通过<option selected="selected">进行了查询<option selected="selected">

在我的代码中,如何让Jsoup返回“ <option selected="selected"> ”而不是数据?

采用:

option[selected]

这表示“具有selected属性的每个option元素”

那应该为您工作(请参阅下面的示例)。 或者,如果有多个option处于selected ,则可以指定属性值: option[selected="selected"]

CSS属性选择器中了解更多信息。

Jsoup的工作示例:

public static void main(String[] args) throws Exception {
    Document doc = Jsoup.connect("http://www.singaporepools.com.sg/Lottery?page=wc_four_d").get();
    Elements content = doc.select("option[selected]");
    System.out.println(content);
}

输出:

<option selected="selected">Select a draw date</option>

暂无
暂无

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

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