我正在尝试下载this one这样的网页内容 并将其写入.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"
答案 0 :(得分:0)
添加ignoreContentType(true)
:
doc = Jsoup.connect(link).ignoreContentType(true).userAgent("Mozilla").get();