如何检索网站的图标?

mob*_*bob 21 favicon web

我想在我的网站上列出精选网站,我认为尊重和使用他们的网站很酷.如何从域中获取JSP或XSLT中的任意URL?我可以启动PHP或javascript,但XSLT是首选的方法.

nLL*_*nLL 63

你也可以这么做

http://s2.googleusercontent.com/s2/favicons?domain_url=http://domain.com

  • 16x16px是可怕的质量. (9认同)
  • 有没有办法获得32x32? (4认同)
  • 但在那种情况下,你没有做好这份工作.谷歌呢. (2认同)

Dan*_*llo 26

要获取网站的图标,您需要加载每个特色网站的索引HTML并检查以下任一项:

HTML:

<link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico">
<link rel="icon" type="image/png" href="http://example.com/image.png">
<link rel="icon" type="image/gif" href="http://example.com/image.gif">
Run Code Online (Sandbox Code Playgroud)

XHTML:

<link rel="icon" type="image/vnd.microsoft.icon" href="/somepath/image.ico" />
<link rel="icon" type="image/png" href="/somepath/image.png" />
<link rel="icon" type="image/gif" href="/somepath/image.gif" />
Run Code Online (Sandbox Code Playgroud)

Internet Explorer可能使用稍微不同的格式:

<link rel="SHORTCUT ICON" href="http://www.example.com/myicon.ico" />
Run Code Online (Sandbox Code Playgroud)

另请注意,由于大多数Web浏览器不需要HTML链接来检索favicon,因此favicon.ico如果找不到上述链接引用,还应检查网站的文档根目录.

使用PHP,可以通过以下方式轻松获取网页的HTML内容file_get_contents($url):

$url = 'http://www.exmaple.com';
$output = file_get_contents($url);
Run Code Online (Sandbox Code Playgroud)

  • 优秀!谢谢你的细节丹尼尔.我将查看PHP教程并告诉您它是如何工作的. (2认同)