Пример #1
0
        public static async Task <List <TradeItem> > GetDataForItem(int itemId, int pageNumber)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(@"https://eu.tamrieltradecentre.com/pc/Trade/");
                var str = await client.GetStringAsync("SearchResult?ItemID=" + itemId + "&SortBy=LastSeen&Order=desc&page=" + pageNumber);

                var list = TradeItem.ParsePage(str);
                foreach (var item in list)
                {
                    item.ItemId = itemId;
                }

                return(list);
            }
        }
Пример #2
0
        public static TradeItem Parse(HtmlNode tr)
        {
            TradeItem item = new TradeItem();

            item.Id = long.Parse(tr.Attributes["data-on-click-link"].Value.Substring(tr.Attributes["data-on-click-link"].Value.LastIndexOf('/') + 1));

            var cells = tr.SelectNodes("td");

            for (int i = 0; i < cells.Count; i++)
            {
                var current = cells[i];
                if (i == 0)
                {
                    item.Name = TrimRemove(current.SelectSingleNode("div").InnerText);
                }
                else if (i == 2)
                {
                    var nodes = current.SelectNodes("div");
                    item.Location  = TrimRemove(nodes[0].InnerText);
                    item.GuildName = TrimRemove(nodes[1].InnerText);
                }
                else if (i == 3)
                {
                    var   nodes        = current.ChildNodes;
                    var   perItem      = TrimRemove(nodes[2].InnerText.Replace(",", "").Replace(".", ","));
                    var   quantityItem = TrimRemove(nodes[6].InnerText);
                    float price;
                    if (float.TryParse(perItem, System.Globalization.NumberStyles.Number, CultureInfo.InvariantCulture, out price))
                    {
                        item.ItemPrice = price;
                    }

                    item.ItemPrice = float.Parse(perItem);
                    item.Quantity  = int.Parse(quantityItem);
                }
                else if (i == 4)
                {
                    item.MinutesAgo = int.Parse(current.Attributes["data-mins-elapsed"].Value);
                    item.PostedDate = DateTime.Now.AddMinutes(-item.MinutesAgo);
                }
            }

            return(item);
        }