//获取图标 从页面上查找 没有就拼接默认
private String findIco(String navUrl) {
String body = HttpUtil.createGet(navUrl).execute().toString();
String str = body.split("/favicon.ico")[0];
int http = str.indexOf("https://",str.length()-100);
if(http==-1){
http = str.indexOf("http://",str.length()-100);
}
if(http==-1){
//说明没有指定 走拼接逻辑
int i = navUrl.indexOf("/",8);//获取网址 拼接 favicon.ico
if(i>0){
navUrl = navUrl.substring(0, i);
}
}else {
navUrl = str.substring(http);
}
return navUrl+"/favicon.ico";
}
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.6.5</version>
</dependency>