private HtmlDocument GetPageHtmlDocument(string pageUrl) { using (KnigoskopWebClient client = new KnigoskopWebClient()) { string pageSources = client.DownloadData(pageUrl); HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(pageSources); return(htmlDocument); } }
private byte[] ProcessImageSource(HtmlNode vCard, HtmlDocument htmlDocument) { string imageUrl = string.Empty; if (vCard != null) { imageUrl = vCard.SelectSingleNode(".//a[@class=\"image\"]/img").Attributes["src"].Value; } else { //try to get image from page if (htmlDocument.DocumentNode.SelectSingleNode(".//a[@class=\"image\"]") != null && htmlDocument.DocumentNode.SelectSingleNode(".//a[@class=\"image\"]/img[@class=\"thumbimage\"]") != null) { imageUrl = htmlDocument.DocumentNode.SelectSingleNode(".//a[@class=\"image\"]/img[@class=\"thumbimage\"]").Attributes["src"].Value; } } if (!string.IsNullOrEmpty(imageUrl)) { if (!imageUrl.ToLower().StartsWith("http://")) { imageUrl = "http:" + imageUrl; } KnigoskopWebClient webClient = new KnigoskopWebClient(); byte[] imageSource = webClient.DownloadImage(imageUrl); if (imageSource != null) { MemoryStream ms = new MemoryStream(imageSource); Image image = Image.FromStream(ms); ms = new MemoryStream(); image.Save(ms, ImageFormat.Jpeg); imageSource = ms.ToArray(); /*using (FileStream fs = new FileStream("TestImage.jpeg", FileMode.Create, FileAccess.Write)) * { * BinaryWriter bw = new BinaryWriter(fs); * bw.Write(imageSource); * bw.Flush(); * }*/ } return(imageSource); } return(null); }