/// <summary> /// Parse market place. /// </summary> /// <returns><see cref="MarketPlace"/></returns> public MarketPlace MarketPlace() { MarketPlace marketPlace = new MarketPlace(); HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//table[@id='target_select']"); if (htmlNode != null) { HtmlNode node = htmlNode.SelectSingleNode("./tr/td"); if (node != null) { string innerText = node.InnerText; int indexOf = innerText.LastIndexOf(' '); if (indexOf > -1) { string[] merchanst = innerText.Substring(indexOf).Trim().Split('/'); marketPlace.AvailableMerchants = Misc.String2Number(merchanst[0]); marketPlace.TotalMerchants = Misc.String2Number(merchanst[1]); } } } if (language.MarketPlace != null) { htmlNode = htmlDocument.DocumentNode.SelectSingleNode(String.Format(CultureInfo.InvariantCulture, "//p[starts-with(text(), '{0}')]", language.MarketPlace.TotalCarry)); if (htmlNode != null) { string text = htmlNode.InnerHtml; string[] spliter = text.Split(new[] { "<b>", "</b>" }, StringSplitOptions.RemoveEmptyEntries); marketPlace.TotalCarry = Misc.String2Number(spliter[1].Trim()); } HtmlNodeCollection htmlNodeCollection = htmlDocument.DocumentNode.SelectNodes("//table[@class='traders']"); if (htmlNodeCollection != null) { foreach (HtmlNode nodeCollection in htmlNodeCollection) { if (nodeCollection != null) { HtmlNode node = nodeCollection.SelectSingleNode("./thead/tr/td[2]/a"); string from = node.InnerText.Trim(); if (from.StartsWith(language.MarketPlace.IncommingTransport)) { marketPlace.TotalIncommingTransports++; } HtmlNodeCollection nodes = nodeCollection.SelectNodes("./tr[@class='res']/td//img"); if (nodes != null) { marketPlace.TotalIncommingWood += Misc.String2Number(nodes[0].NextSibling.InnerText); marketPlace.TotalIncommingClay += Misc.String2Number(nodes[1].NextSibling.InnerText); marketPlace.TotalIncommingIron += Misc.String2Number(nodes[2].NextSibling.InnerText); marketPlace.TotalIncommingCrop += Misc.String2Number(nodes[3].NextSibling.InnerText); } } } } } return marketPlace; }
public void ParseUnknownDestination() { parseSucceeded = false; if (language == null) return; source = account.GetVillage(queue.SourceVillage.Id); if (source == null) return; string url = String.Format(CultureInfo.InvariantCulture, "{0}build.php?newdid={1}&gid=17", settings.LoginData.Servername, source.Id); htmlDocument = htmlWeb.Load(url); if (htmlDocument == null) return; HtmlParser htmlParser = new HtmlParser(htmlDocument, language); marketPlaceSource = htmlParser.MarketPlace(); if (marketPlaceSource == null) return; destination = queue.DestinationVillage; parseSucceeded = true; }