Monday, November 25, 2024 1:10:25 PM
public static string GetFirstImageUrl(string htmlContent)
{
if (string.IsNullOrEmpty(htmlContent)) return null;
HTMLDocument doc = new HTMLDocument();
IHTMLDocument2 doc2 = (doc as IHTMLDocument2);
doc2.write(htmlContent as object);
IHTMLElementCollection imgs = doc.getElementsByTagName("img");
int i = 0;
while (true)
{
IHTMLElement img = imgs.item(i);
if (img != null)
{
string ImageUrl = img.getAttribute("src") as string;
Stream str = null;
HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(ImageUrl);
HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
str = wRes.GetResponseStream();
var imageOrig = System.Drawing.Image.FromStream(str);
int height = imageOrig.Height;
int width = imageOrig.Width;
if (height > 50 && width > 50)
{
return ImageUrl;
}
else
{
i++;
continue;
}
}
else
{
break;
}
}
return null;
}
public static bool IsRilevant(SyndicationItem item)
{
return IsRilevant(item.Title) || IsRilevant(item.Summary) || IsRilevant(item.Content as TextSyndicationContent);
}
public static bool IsRilevant(TextSyndicationContent textContent)
{
if (textContent == null) return false;
else return IsRilevant(textContent.Text);
}
public static bool IsRilevant(string text)
{
if (text == null) return false;
return text.ToLower().Contains("keyword");
}
}
}