【问题标题】:Clean html with HtmlCleaner使用 HtmlCleaner 清理 html
【发布时间】:2013-09-22 08:19:22
【问题描述】:

我有一个 html 文件存储在手机上,我想用 HtmlCleaner 清理它并查看输出结果。这是我的代码:

public void cleanHtml() throws IOException{
    HtmlCleaner cleaner = new HtmlCleaner();

    CleanerProperties props = cleaner.getProperties();

    TagNode node = cleaner.clean(htmlToClean);

    new PrettyXmlSerializer(props).writeToFile(node, "4c.xml");
}

这没有任何作用。我想在手机上的某处查看 .xml 或已清理的 .html 文件。

这是 htmlToClean 变量:

htmlToClean = new File(Environment.getExternalStorageDirectory().getPath() + "/Android/data/com.whizzapps.stpsurniki/4c.html");

【问题讨论】:

    标签: java android htmlcleaner


    【解决方案1】:

    这样解决了:

    private class cleanHtml extends AsyncTask<Void, Void, Void>{
    
        @Override
        protected Void doInBackground(Void... arg0) {
            try {
                HtmlCleaner cleaner = new HtmlCleaner();
                String url = "https://www.easistent.com/urniki/263/razredi/16515";
                TagNode node = cleaner.clean(new URL(url));
                CleanerProperties props = cleaner.getProperties();
                String fileName = Environment.getExternalStorageDirectory().getPath() + "/Android/data/com.whizzapps.stpsurniki/cleaned.html";
                new PrettyXmlSerializer(props).writeToFile(node, fileName, "utf-8");
                Log.i("TAG", "AsyncTask done!");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 2016-02-04
      相关资源
      最近更新 更多