(笔记)
获取网页的动态内容参考
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);