Пример #1
0
            public void SelectMenu(HtmlDocument doc)
            {
                HtmlNode node = doc.DocumentNode.SelectSingleNode(".//nav[@id='main-menu']");

                HtmlNodeCollection nodes = node.SelectNodes(".//li[@class='cat-item']");

                SortedSet <string> tmpMenuList = new SortedSet <string>();

                foreach (HtmlNode n in nodes)
                {
                    try
                    {
                        string href = n.SelectSingleNode(".//a").Attributes["href"].Value;
                        href = parser.ConcatHref(parser.connectionStringBuilder.GetCeonnectionString(), href);
                        tmpMenuList.Add(href);
                    }
                    catch
                    {
                    }
                }

                parser.SetState(new StateParcerSubMenu(parser));

                tmpMenuList.ExceptWith(parser.menuList);
                foreach (string s in tmpMenuList)
                {
                    Console.WriteLine(s);
                }

                parser.menuList.UnionWith(tmpMenuList);
                foreach (string href in tmpMenuList)
                {
                    parser.Select(new CPath(href));
                }
            }
Пример #2
0
            public void SelectMenu(HtmlDocument doc)
            {
                HtmlNode node = doc.DocumentNode.SelectSingleNode(".//ul[@class='category-nav']");

                if (node == null)
                {
                    return;
                }

                HtmlNodeCollection nodes = node.SelectNodes(".//li//ul//li//a");

                if (nodes == null)
                {
                    return;
                }

                SortedSet <string> tmpMenuList = new SortedSet <string>();

                foreach (HtmlNode n in nodes)
                {
                    try
                    {
                        string href = n.Attributes["href"].Value;
                        href = parser.ConcatHref(parser.connectionStringBuilder.GetCeonnectionString(), href);
                        tmpMenuList.Add(href);
                    }
                    catch
                    {
                    }
                }

                tmpMenuList.ExceptWith(parser.menuList);
                foreach (string s in tmpMenuList)
                {
                    Console.WriteLine(s);
                }

                parser.menuList.UnionWith(tmpMenuList);
                if (tmpMenuList.Any())
                {
                    Console.WriteLine("total: " + parser.menuList.Count + "; add: " + tmpMenuList.Count);
                }
                foreach (string href in tmpMenuList)
                {
                    parser.Select(new CPath(href));
                }
            }