Html工具类

public class HtmlUtil {
/**
* 单例工具类
*/
public HtmlUtil() {
}



public static Document getDoc(String url)throws IOException
{
File file = new File(url);

if(file.exists())
{
Document doc = Jsoup.parse(file,"GBK");//Jsoup.parse(new URL(url).openStream(), "GBK", url);//
return doc;
}else{
System.out.println("文件不存在:"+url);
return null;
}



}

public static Document getDocUrl(String url)throws IOException
{
File file = new File(url);

if(file.exists())
{

return Jsoup.parse(new URL(url).openStream(), "GBK", url);
}else{
System.out.println("文件不存在:"+url);
return null;
}



}

public static Elements getTables(Document doc)
{
Elements tables = doc.getElementsByTag("table");
return tables;
}
public static String subZeroAndDot(String s) {
if (s != null && !s.equals(" ") && s.indexOf(".") > 0) {
s = s.replaceAll("0+?$", "");// 去掉多余的0
s = s.replaceAll("[.]$", "");// 如最后一位是.则去掉
s = s.replaceAll(" ", "");// 如最后一位是.则去掉
/*s = s.replaceAll(".", "");// 如最后一位是.则去掉
s = s.replaceAll(".0", "");// 如最后一位是.则去掉
s = StringUtils.toString(Math.floor(Double.parseDouble(s)));*/
}
return s;
}

public static double getMaxDouble(List list) {

double max = (double) Collections.max(list);

return max;
}

public static double getMinDouble(List list) {

double min = (double) Collections.min(list);

return min;
}


}

posted on 2020-07-27 17:22  TheKingJames  阅读(105)  评论(0编辑  收藏  举报