public async Task <PoePage> GetPoeWikiPage(string poeUrl) { using (WebClient wc = new WebClient()) { Stream website = await wc.OpenReadTaskAsync(new Uri(poeUrl, UriKind.Absolute)); using (StreamReader sr = new StreamReader(website)) { HtmlDocument poePage = new HtmlDocument(); poePage.LoadHtml(sr.ReadToEnd()); var itemBox = poePage.DocumentNode.SelectSingleNode("//span[contains(@class,'infobox-page-container')]"); if (itemBox != null) { return(GetPoeItemPage(itemBox)); } var divCard = poePage.DocumentNode.SelectSingleNode("//div[contains(@class, 'item-box -divicard -floatright')]"); if (divCard != null) { return(PoePage.DivinationPage(divCard.OuterHtml)); } var keystone = poePage.DocumentNode.SelectSingleNode("//div[contains(@class, 'infocard passive-keystone')]"); if (keystone != null) { return(PoePage.KeystonePage(keystone.OuterHtml)); } return(PoePage.InvalidPage()); } } }
public string GetWikiHtml(PoePage page) { string itemboxTemplateLocation = ConfigurationManager.AppSettings[PoeWikiSettings.ItemBoxLocation]; string itemboxTemplate = File.ReadAllText(itemboxTemplateLocation); return(itemboxTemplate.Replace("#itembox", page.Html)); }
public PoePage GetPoeItemPage(HtmlNode itemBox) { if (itemBox != null) { //Remove everything other than the first var totalChildren = itemBox.ChildNodes.Count; for (var i = 1; i < totalChildren; i++) { itemBox.ChildNodes[1].Remove(); } return(PoePage.ItemPage(itemBox.InnerHtml)); } return(PoePage.InvalidPage()); }
public MemoryStream GetWikiImage(PoePage itemBox) { var result = GetWikiHtml(itemBox); var convert = new NReco.ImageGenerator.HtmlToImageConverter { Width = 348, CustomArgs = "--quality 85", Zoom = 2 }; var image = convert.GenerateImage(result, ImageFormat.Png); var stream = new MemoryStream(image) { Position = 0 }; return(stream); }