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