我已经尝试使用Java或Python保存完整的页面,我还尝试了selenium和wget。最后,我选择了HtmlUnit,因为它可以通过使用save()轻松实现。
我的页面被截断了,中文字符显示为"?“。有什么方法可以改变编码吗?或者,是否有其他工具可以保存整个页面?
我的代码:
WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
try {
HtmlPage htmlPage = webClient.getPage("http://www.fulijr.com/");
File file = new File("fulijr.html");
htmlPage.save(file);
} catch (IOException e) {
e.printStackTrace();
}结果是:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
<meta name="keywords" content="????,????????,??????P2P????"/>
<meta name="description" content="??????????P2P???????????????????????????????????????????????????????????????????????????????????P2P???????????????????????????????????????????????????????????????????????????"/>
...发布于 2018-11-25 04:09:15
这是当前版本的HtmlUnit (版本2.33)中的一个错误。已修复此问题;如果有新的快照构建可用,将通知https://twitter.com/HtmlUnit。
https://stackoverflow.com/questions/53444689
复制相似问题