Javascript 从网站中提取favicon
我正在尝试从网站url中提取favicon。我正在使用Javascript 从网站中提取favicon,javascript,jquery,html,asp.net,favicon,Javascript,Jquery,Html,Asp.net,Favicon,我正在尝试从网站url中提取favicon。我正在使用HtmlAgilityPack。我有一些但不是全部。我认为问题在于执行上的差异。我国目前的战略是 HtmlNode imageNode = head.SelectSingleNode("//link[@rel='shortcut icon' or @rel='apple-touch-icon' or @rel='icon' or @rel='apple-touch-icon-precomposed'] | //link[@ty
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;
}
但我还是错过了一些东西。所以我需要知道favicon的其他代码
<link rel="icon" type="image/png" href="http://yourblog.com/favicon.png" />
及
实际上,添加favicon的正确方法是通过插件,这样添加的favicon就不依赖于主题
此外,您可能缺少某些文件类型。请转到下面的链接下载网站的favicon 打开链接并单击另存为图像以下载它
将codegena.com替换为您要下载favicon的域名。我不明白。你为什么需要这些设备?那是另一个问题。。说我需要它们作为书签…很抱歉你不理解这个问题。。我想提取我正在浏览的其他网站的favicon。这就是为什么我要告诉你favicon被放入网站的方式。为什么不将web url与favicon一起提取,这样就可以看到favicon没有从哪个url中提取出来。然后看看这些urlsYes中的方法,我正在这样做,但仍然不知道。。。比如查看这个网站,告诉我他们是怎么做的。。我不知道他们是怎么做的。。是的,我明白了。。。但是浏览器是如何获得这种方法的。。我将不得不做相当乏味的工作来得到这个…是的,因为你所做的不是一个简单的任务,不可能总是完全完成。
<link rel="shortcut icon" href="http://example.com/favicon.ico" type="image/x-icon" />