使用HtmlUnit保存完整页时截断的文本

2024-03-28 13:41:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试过用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???????????????????????????????????????????????????????????????????????????"/>
        ...

Tags: httpnewsavehtmlp2p页面contentmeta