如何在 Android 中使用 jsoup 获取网站 image/logo
How to get the website image/logo with jsoup in Android
我正在尝试在 android 中使用 jsoup 显示 URL 的预览。
但我现在担心的是我无法决定在预览中显示哪个图像。我想要的是显示网站图像,例如 Facebook 的 "F" 徽标,Twitter 的 "t" 徽标。
那么,有人可以帮我解决这个问题吗?
我猜您正在寻找 favIcon。
收藏夹图标可能采用以下方式-
喜欢
<head>
<link rel="icon" href="http://example.com/image.ico" />
</head>
或
<head>
<link rel="icon" href="http://example.com/image.png" />
</head>
或
<head>
<meta content="/images/google_favicon_128.png" itemprop="image" />
</head>
拳头2种-
Connection con2=Jsoup.connect(url);
Document doc = con2.get();
Element e1=doc.head().select("link[href~=.*\.(ico|png)]").first(); // example type 1 & 2
String imageUrl1=e1.attr("href");
Element e2 = doc.head().select("meta[itemprop=image]").first(); //example type 3
String imageUrl2=e2.attr("itemprop");
然后在 ImageView 中加载 imageUrl。
我正在尝试在 android 中使用 jsoup 显示 URL 的预览。
但我现在担心的是我无法决定在预览中显示哪个图像。我想要的是显示网站图像,例如 Facebook 的 "F" 徽标,Twitter 的 "t" 徽标。
那么,有人可以帮我解决这个问题吗?
我猜您正在寻找 favIcon。
收藏夹图标可能采用以下方式-
喜欢
<head>
<link rel="icon" href="http://example.com/image.ico" />
</head>
或
<head>
<link rel="icon" href="http://example.com/image.png" />
</head>
或
<head>
<meta content="/images/google_favicon_128.png" itemprop="image" />
</head>
拳头2种-
Connection con2=Jsoup.connect(url);
Document doc = con2.get();
Element e1=doc.head().select("link[href~=.*\.(ico|png)]").first(); // example type 1 & 2
String imageUrl1=e1.attr("href");
Element e2 = doc.head().select("meta[itemprop=image]").first(); //example type 3
String imageUrl2=e2.attr("itemprop");
然后在 ImageView 中加载 imageUrl。