在J汤中,当我用CSS查询option
解析URL http://www.singaporepools.com.sg/Lottery?page=wc_four_d
时,我的第一个元素得到了"选择绘制日期",查询为<option selected="selected">
。
在我的代码中,如何让Jsoup返回"<option selected="selected">
",而不是数据?
使用:
option[selected]
这意味着"每个具有selected
属性的option
元素"。
这应该对您有效(参见下面的示例)。或者,如果有多个属性为selected
的option
,则可以指定属性值:option[selected="selected"]
。
在CSS属性选择器中了解更多信息
J汤工作示例:
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>