Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey all,

I was just wondering, is there a proper way to get a website's favicon without just getting it from
VB.NET
"http" + Url.Host + "/favicon.ico"
? I know that a website usually sets its favicon like this:
HTML
<meta content="/images/myfavicon.png" itemprop="image">

OR

<link rel="icon" type="image/x-icon" href="/myfavicon.ico">


Is there a way I can search through the website's HTML code and get the icon from those tags using CEF (ChromiumEmbedFramework for VB.NET WinForms) or a webclient (I'm still not sure how to get the source code from a website using CEF).

I would really appreciate any help! :D
Posted

1 solution

Ok, I managed to figure it out myself. I decided to use a webclient and use Google's Api to get the website favicon:

VB
Dim Urlh As New Uri("http://www.google.com/s2/favicons?domain=" + New Uri(Browser.Address).Host)
Dim Img As Image = New Bitmap(New IO.MemoryStream(New WebClient().DownloadData(Urlh)))
Dim Img2 As New Bitmap(Img)
Dim Img3 As Icon
Dim oIcon As Icon = Img3.FromHandle(Img2.GetHicon)

Me.Icon = oIcon


Hope this helps anyone else! ;)
 
Share this answer
 
Comments
Member 13994932 29-Sep-19 10:13am    
Google favicons service gives a 16×16 sized icon. That is the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900