如何使用 Selenium 获取网站的 favicon
我需要获取网站的图标.
I need to get web site's favicon.
我该怎么做?
您将无法使用 Selenium 获取网站图标,您必须使用另一个程序来获取它.您能够获得它的唯一方法是,如果您的网站将 favicon.ico 呈现为诸如
You won't be able to get the favicon with Selenium you would have to use another program to grab it. The only way you would be able to get it is if your website rendered the favicon.ico as a link such as
<link rel="shortcut icon"
href="http://example.com/myicon.ico" />
然而,网站通常只是将 favicon.ico 存储在根目录中,并且在页面请求时浏览器会检索它并将其放置在地址栏或选项卡或使用 favicon 的任何地方.如果这是您的网站图标的呈现方式,那么将没有代码或任何可使用 Selenium 搜索的内容.
However typically websites just store the favicon.ico in the root directory and on page request the browser retrieves it and drops it in the address bar or tab or wherever favicons are used. If this is how your favicon is rendered then there will be no code or anything to search for with Selenium.
上述代码在运行时也对 IE7 有一些错误支持.
Also the above code while it does work has some buggy support for IE7.