所以我试图从某个网站获取一些数据。当应用程序首次启动时,它会下载某个网站的 html 文件并对其进行清理。
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;
}
}
现在我知道我可以使用 XPath 使用 HtmlCleaner 来解析 html,但我对 XPath 一无所知。我很确定在清理文件后用 Jsoup 解析它会更容易。这个可以吗?