You can use HTML agility pack or XmlDocument and get favicon. The following code will bring the path of website’s icon.
public JsonResult GetFavIcon(string term)
{
string htmlCode;
try
{
using (WebClient client = new WebClient())
{
htmlCode = client.DownloadString(term);
}
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(htmlCode);
if (doc.DocumentNode != null)
{
var favicon = "/favicon.ico";
var el =doc.DocumentNode.SelectSingleNode("/html/head/link[@rel='shortcut icon' and@href]");
}
return Json(submit, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
return null;
}
}
Post your comments / questions
Recent Article
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
- expected str, bytes or os.PathLike object, not JpegImageFile - Python
Related Article