我試圖下載this one 等頁面的內容,並將它寫入.txt文件供以後使用。嘗試使用jsoup將URL事件下載到.txt文件中
doc = Jsoup.connect(link).userAgent("Mozilla").get();
String cityInfo = doc.html();
int index = cityInfo.indexOf("},"); // keeps just the first object as it has the highest score.
String cityInfo1 = cityInfo.substring(index+1) + "}]}"; // gets the object in the correct format as some characters are not selected when downloading
bw1.write(cityInfo1); //saves json object into text file
我不斷收到此錯誤,如果我使用ignoreContentType(true)
方法,它只是擺脫錯誤的和我的文本文件保持爲空。
"Exception in thread "main"
org.jsoup.UnsupportedMimeTypeException: Unhandled content type.
Must be text/*, application/xml, or application/xhtml+xml.
Mimetype=application/json, URL=http://transport.opendata.ch/v1/locations?query=Aarau"
爲什麼要用Jsoup的JSON格式的數據? – Tim
我想只將整個頁面作爲文本下載並稍後處理。你會建議什麼? – BlueWookie
查看JSON格式:https://en.wikipedia.org/wiki/JSON – Tim