示例#1
0
        private static void parseResults(HtmlAgilityPack.HtmlDocument htmlDoc, List <results> res)
        {
            // use HtmlAgilityPack to loop through the structure of the HTML and try to find the main nodes.
            // seems all nodes are demarcated by whatever 'match ds_collapse_flag' is
            foreach (HtmlNode mdiv in htmlDoc.DocumentNode.SelectNodes("//a[contains(@class,'" + cS.steamSearchContainer + "')]"))
            {
                results r = new results();

                // Load each individual node into a new HtmlDocument
                HtmlAgilityPack.HtmlDocument innerDoc = new HtmlAgilityPack.HtmlDocument();
                innerDoc.LoadHtml(mdiv.InnerHtml);

                // now find the nodes we're looking for
                HtmlNode div = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSearchGameName + "')]");
                // if found, HtmlAgilityPack returns what you're looking for in innerhtml
                // --> else {blow up}
                r.theGame = div.InnerHtml;

                div        = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSearchImage + "')]");
                r.theImage = div.InnerHtml;

                div        = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSearchPrice + "')]");
                r.thePrice = gT.ReplaceEx(div.InnerHtml, "$", "");

                // add the instance of results() to the res list
                res.Add(r);
            }
        }
示例#2
0
        private static void parseResults(HtmlAgilityPack.HtmlDocument htmlDoc, List <results> res, string classname)
        {
            // use HtmlAgilityPack to loop through the structure of the HTML and try to find the main nodes.
            foreach (HtmlNode mdiv in htmlDoc.DocumentNode.SelectNodes("//a[contains(@class,'" + classname + "')]"))
            {
                results r = new results();

                // Load each individual node into a new HtmlDocument
                HtmlAgilityPack.HtmlDocument innerDoc = new HtmlAgilityPack.HtmlDocument();
                innerDoc.LoadHtml(mdiv.InnerHtml);

                // now find the nodes we're looking for
                HtmlNode div = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSpecialsGameName + "')]");
                // if found, HtmlAgilityPack returns what you're looking for in innerhtml
                // --> else {blow up}
                r.theGame = div.InnerHtml;

                div        = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSpecialsImage + "')]");
                r.theImage = div.InnerHtml;

                // the discounts and prices are squirrelled away in here, forcing us to do a couple more loads
                div = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSpecialsMoneySection + "')]");
                innerDoc.LoadHtml(div.InnerHtml);
                div = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSpecialsDiscount + "')]");

                string discount = gT.ReplaceEx(div.InnerText, "\r\n", "").Trim();

                div = innerDoc.DocumentNode.SelectSingleNode("//div[contains(@class,'" + cS.steamSpecialsPrices + "')]");
                string   p     = gT.ReplaceEx(div.InnerText, "\r\n", "").Trim();
                string[] p1    = p.Split('$');
                string   price = "";
                if (p1.Length == 3)
                {
                    price = "Disc " + discount + " $" + p1[1] + " -> $" + p1[2];
                }
                else
                {
                    price = p;
                }

                r.thePrice = price;

                // add the instance of results() to the res list
                res.Add(r);
            }
        }