我想從網站的網址提取圖標。我正在使用HtmlAgilityPack
。我收到一些圖標,但不是全部。我認爲問題在於實施方面的差異。礦目前的策略是..從網站提取圖標
HtmlNode imageNode = head.SelectSingleNode("//link[@rel='shortcut icon' or @rel='apple-touch-icon' or @rel='icon' or @rel='apple-touch-icon-precomposed'] | //link[@type='image/png' or @type='image/gif' or @type='image/vnd.microsoft.icon']");
imageNode = head.SelectSingleNode("link[@rel='image_src']");
和開放的圖形方法
private LinkDetails GetOpenGraphInfo(LinkDetails linkDetails, HtmlNode head)
{
foreach (HtmlNode headNode in head.ChildNodes)
{
switch (headNode.Name.ToLower())
{
case "link": break;
case "meta":
if (headNode.Attributes["property"] != null && headNode.Attributes["content"] != null)
{
switch (headNode.Attributes["property"].Value.ToLower())
{
case "og:title":
linkDetails.Title = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:type":
linkDetails.Type = headNode.Attributes["content"].Value;
break;
case "og:url":
linkDetails.Url = headNode.Attributes["content"].Value;
break;
case "og:image":
linkDetails.Image = new ImageLink(headNode.Attributes["content"].Value, linkDetails.Url);
break;
case "og:site_name":
linkDetails.SiteName = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:description":
linkDetails.Description = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:email":
linkDetails.Email = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:phone_number":
linkDetails.PhoneNumber = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
case "og:fax_number":
linkDetails.FaxNumber = HttpUtility.HtmlDecode(headNode.Attributes["content"].Value);
break;
}
}
break;
}
}
return linkDetails;
}
但還是我缺少一些網站圖示。所以我需要知道如何編碼的圖標。
我不明白這一點。你爲什麼需要這些圖標? –
這是另一個問題..說我需要他們的書籤... –