java 如何获取网页的动态内容,并解析网页内容


(笔记)

获取网页的动态内容参考

https://stackoverflow.com/questions/42446990/parse-html-table-to-json-using-jsoup-in-java

maven:

<!--将html转换为Map-->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.3</version>
</dependency>

实现:
public String TableToJson(String url) throws JSONException { Document doc = Jsoup.connect(url).get(); JSONObject jsonParentObject = new JSONObject(); //JSONArray list = new JSONArray(); for (Element table : doc.select("table")) { for (Element row : table.select("tr")) { JSONObject jsonObject = new JSONObject(); Elements tds = row.select("td"); String Name = tds.get(0).text(); String Group = tds.get(1).text(); String Code = tds.get(2).text(); String Lesson = tds.get(3).text(); String Day1 = tds.get(4).text(); String Day2 = tds.get(5).text(); String Day3= tds.get(6).text(); jsonObject.put("Group", Group); jsonObject.put("Code", Code); jsonObject.put("Lesson", Lesson); jsonObject.put("Day1", Day1); jsonObject.put("Day2", Day2); jsonObject.put("Day3", Day3); jsonParentObject.put(Name,jsonObject); } } return jsonParentObject.toString(); }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM