当尝试解析网站的html页面时,它会崩溃,并出现以下错误:
java.io.IOException:Mark已失效。
我的代码之一是:
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);
}
我想要解析的网站的大小大约是2MB。当我调试代码时,我看到在java包ConstrainableInputStream.java
方法中:
public void reset() throws IOException {
super.reset();remaining = maxSize - markpos;
}
并返回markpos= -1
,然后转到异常。
我怎样才能解决这个问题?
发布于 2019-11-21 10:13:53
这帮了我:
GET: .execute().bufferUp().parse();
POST: .method(Connection.Method.POST).execute().bufferUp().parse();
发布于 2017-12-10 17:26:47
我找到了这个问题的解决办法。问题是缓冲区超载。使用以下代码解决:
BufferedReader br = null;
try{
connection = new URL(xml).openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
content = content +line;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Document document = Jsoup.parse(content);
发布于 2020-02-28 15:00:04
在从1.11.3升级到1.12.2时,我也有同样的例外--试着降低您的受抚养人的等级
https://stackoverflow.com/questions/47733379
复制相似问题