<div class="qml-stem"><p style=""><span style="font-family: 宋体;">读一读,猜一猜。</span></p><p style=""><span style="font-family: 宋体;">什么鸟跑得快,不爱树林爱沙漠?(<span style="font-family: 'Times New Roman'" qml-space-size="2"> </span>)</span></p><div class=" qml-og"><table class="qml-og" style="width:100%"><tr><td>A. <span class="qml-op"><span style="font-family: 宋体;">山椒鸟</span></span></td><td>B. <span class="qml-op"><span style="font-family: 宋体;">鸵鸟</span></span></td><td colspan="1">C. <span class="qml-op"><span style="font-family: 宋体;">犀鸟</span></span></td></tr></table></div></div> 怎么判断这段html是否有D选项 用java 代码实现
时间: 2023-07-19 07:25:56 浏览: 163
可以使用Java中的正则表达式来判断这段HTML代码中是否包含D选项。以下是示例代码:
```java
String html = "<div class=\"qml-stem\"><p style=\"\"><span style=\"font-family: 宋体;\">读一读,猜一猜。</span></p><p style=\"\"><span style=\"font-family: 宋体;\">什么鸟跑得快,不爱树林爱沙漠?(<span style=\"font-family: 'Times New Roman'\" qml-space-size=\"2\"> </span>)</span></p><div class=\" qml-og\"><table class=\"qml-og\" style=\"width:100%\"><tr><td>A. <span class=\"qml-op\"><span style=\"font-family: 宋体;\">山椒鸟</span></span></td><td>B. <span class=\"qml-op\"><span style=\"font-family: 宋体;\">鸵鸟</span></span></td><td colspan=\"1\">C. <span class=\"qml-op\"><span style=\"font-family: 宋体;\">犀鸟</span></span></td></tr></table></div></div>";
String pattern = "<td[^>]*>[^<]*D\\.\\s*<[^>]*>";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(html);
if (m.find()) {
System.out.println("存在D选项");
} else {
System.out.println("不存在D选项");
}
```
输出结果为“不存在D选项”。
阅读全文