java 、jsoup正则表达式

如何通过正则表达式或者jsoup将19040172b-1、 SQL Server开发 、郑尚 、3-5,7-14(周) 、东区综合楼D-101 提取出来?,


 <div id="AE9D7F630640426F8457A661607D2B8E-5-2" style="display: none;" class="kbcontent">

  19040172b-1

  <br>SQL Server开发

  <br>

  <font title="老师">郑尚</font>

  <br>

  <font title="周次(节次)">3-5,7-14(周)</font>

  <br>

  <font title="教室">东区综合楼D-101</font>

  <br>

 </div>

已尝试下列办法均失败


1. Pattern pattern = Pattern.compile(">(.*?)<br>");


2. Elements msg = doc.select(":matchesOwn([>.*?<br>])");


翻翻过去那场雪
浏览 716回答 3
3回答

侃侃无极

Document document = Jsoup.parse("<div id=\"AE9D7F630640426F8457A661607D2B8E-5-2\" style=\"display: none;\" class=\"kbcontent\"> 19040172b-1 <br>SQL Server开发 <br> <font title=\"老师\">郑尚</font> <br> <font title=\"周次(节次)\">3-5,7-14(周)</font> <br> <font title=\"教室\">东区综合楼D-101</font> <br> </div>");System.out.println(document.text());Output:19040172b-1 SQL Server开发 郑尚 3-5,7-14(周) 东区综合楼D-101不知道是否满足楼主的需求?Document document = Jsoup.parse("<div id=\"AE9D7F630640426F8457A661607D2B8E-5-2\" style=\"display: none;\" class=\"kbcontent\"> 19040172b-1 <br>SQL Server开发 <br> <font title=\"老师\">郑尚</font> <br> <font title=\"周次(节次)\">3-5,7-14(周)</font> <br> <font title=\"教室\">东区综合楼D-101</font> <br> </div>");Element div = document.getElementById("AE9D7F630640426F8457A661607D2B8E-5-2");TextNode n1 = (TextNode) div.childNode(0);System.out.println(n1.text()); // 19040172b-1TextNode n2 = (TextNode) div.childNode(2);System.out.println(n2.text()); // SQL Server开发// ...如果楼主的格式是固定的直接像上面这样解析HTML会比较好一些,不需要REGEX。

动漫人物

String html = "<div id=\"AE9D7F630640426F8457A661607D2B8E-5-2\" style=\"display: none;\" class=\"kbcontent\">&nbsp; 19040172b-1&nbsp; <br>SQL Server Develop&nbsp; <br>&nbsp; <font title=\"teacher\">zheng</font>&nbsp; <br>&nbsp; <font title=\"week\">3-5,7-14</font>&nbsp; <br>&nbsp; <font title=\"classroom\">D-101</font>&nbsp; <br> </div> ";&nbsp; &nbsp; &nbsp; &nbsp; html = html.replaceAll("<br>", "#~#");&nbsp; &nbsp; &nbsp; &nbsp; Document doc = Jsoup.parse(html.toString());&nbsp; &nbsp; &nbsp; &nbsp; String newHtml = doc.text();&nbsp; &nbsp; &nbsp; &nbsp; String[] ary = newHtml.split("#~#");&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0;i < ary.length;i++){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(ary[i]);&nbsp; &nbsp; &nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java