public IEnumerable <App> MapHtmlToApps(string q) { IList <App> apps = new List <App>(); HtmlWeb web = new HtmlWeb(); HtmlDocument html = web.Load(q); string divClass = "card-content id-track-click id-track-impression"; var cardDivs = html.DocumentNode.Descendants("div") .Where(ts => ts.GetAttributeValue("class", string.Empty) == divClass); foreach (var cardDiv in cardDivs) { var names = GetDescendents(cardDiv, "a", "class", "title"); var subtitles = GetDescendents(cardDiv, "a", "class", "subtitle"); var prices = GetDescendents(cardDiv, "span", "class", "display-price"); var descriptions = GetDescendents(cardDiv, "div", "class", "description"); var ratings = GetDescendents(cardDiv, "div", "class", "current-rating"); var icon = GetDescendents(cardDiv, "img", "class", "cover-image"); for (int index = 0; index < names.Length; index++) { string rating = "0"; if (ratings.Length > 0) { rating = GooglePlayUtils.GetRating( ratings[index].GetAttributeValue("style", string.Empty) ); } App app = new App() { Name = names[index].InnerText, SubTitle = subtitles[index].InnerText, Price = prices.Length != 0 ? prices[index].InnerText : string.Empty, Description = descriptions[index].InnerText, Package = names[index].GetAttributeValue("href", string.Empty).Split('=')[1], Rating = rating, Icon = icon[index].GetAttributeValue("src", string.Empty) }; apps.Add(app); } } return(apps); }
public App Get(string id, string country) { HtmlWeb web = new HtmlWeb(); string url = $"https://play.google.com/store/apps/details?id={id}&gl={country}"; HtmlDocument html = web.Load(url); string divClass = "details-wrapper apps square-cover id-track-partial-impression id-deep-link-item"; var divs = GetNode(html.DocumentNode, "div", "class", divClass); App app = new App() { Package = id, Name = GetNode(divs, "div", "class", "id-app-title").InnerText, SubTitle = GetNode(divs, "span", "itemprop", "name").InnerText, Description = GetNode(divs, "div", "jsname", "C4s9Ed").InnerText, Link = url.Split('&')[0], Icon = GetNode(divs, "img", "class", "cover-image") .GetAttributeValue("src", string.Empty), Category = GetNode(divs, "a", "class", "document-subtitle category") .GetAttributeValue("href", string.Empty).Split('/')[4], Screenshots = GetNode(divs, "div", "class", "thumbnails") .Descendants("img") .Select(ts => ts.GetAttributeValue("src", string.Empty)) .ToArray() }; app.Rating = GooglePlayUtils.GetRating( GetNode(divs, "div", "class", "tiny-star star-rating-non-editable-container") .Descendants("div") .FirstOrDefault(ts => ts.GetAttributeValue("class", string.Empty) == "current-rating") .GetAttributeValue("style", string.Empty) ); app.RankingCategory = GetRankingPosition(app.Category, id); app.PositionOverall = GetRankingPosition(app.Category, id, country); return(app); }