当尝试解析网站的 html 页面时,它会因错误而崩溃:
java.io.IOException:标记已失效。
我的部分代码:
String xml = xxxxxx;
try {
Document document = Jsoup.connect(xml).maxBodySize(1024*1024*10)
.timeout(0).ignoreContentType(true)
.parser(Parser.xmlParser()).get();
Elements elements = document.body().select("td.hotv_text:eq(0)");
for (Element element : elements) {
Element element1 = element.select("a[href].hotv_text").first();
hashMap.put(element.text(), element1.attr("abs:href"));
}
} catch (HttpStatusException ex) {
Log.i("GyWueInetSvc", "Exception while JSoup connect:" + xml +" cause:"+ ex.getMessage());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Socket timeout: " + e.getMessage(), e);
}
Run Code Online (Sandbox Code Playgroud)
我要解析的网站大小约为 2MB。当我调试代码时,我看到在 java 包ConstrainableInputStream.java方法中:
public void reset() throws IOException {
super.reset();remaining = maxSize - …Run Code Online (Sandbox Code Playgroud)