示例#1
0
        public void StartHistoryRendom(String title)
        {
            categoryList = new List <CategoryTree>();
            var    webClient = new WebClient();
            string url       = urlWikipedia + title + "&cmlimit=500&format=json&utf8=";

            var pageSourceCode = webClient.DownloadString(url);

            byte[]         bytes              = Encoding.Default.GetBytes(pageSourceCode);
            String         myString           = Encoding.UTF8.GetString(bytes);
            CategoriesList mainlistCategories = JsonConvert.DeserializeObject <CategoriesList>(myString);

            List <categorymembers> cm = mainlistCategories.query.getCategorymembersList();

            CategoryTree tr = new CategoryTree();

            tr.CatgoryName = title;
            tr.PagesList   = cm;
            categoryList.Add(tr);


            do
            {
                String categoryName = getRendomeCatgoryTitle(cm);
                if (categoryName.Equals("notfind"))
                {
                    break;
                }

                cm = getCategoryTree(categoryName);

                CategoryTree tree = new CategoryTree();
                tree.CatgoryName = categoryName;
                tree.PagesList   = cm;
                categoryList.Add(tree);
            } while (true);



            Pagename page = getRendomPage();

            startHtml(page);
        }
示例#2
0
        private void startHtml(Pagename page)
        {
            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(page.extract);
            IEnumerable <HtmlAgilityPack.HtmlNode> forms;

            //      forms = htmlDoc.DocumentNode.Descendants("h");
            //     List<HtmlAgilityPack.HtmlNode> h = forms.ToList();

            //       forms = htmlDoc.DocumentNode.Descendants("h1");
            //      List<HtmlAgilityPack.HtmlNode> h1 = forms.ToList();

//            forms = htmlDoc.DocumentNode.Descendants("h2");
//          List<HtmlAgilityPack.HtmlNode> h2 = forms.ToList();

            //          forms = htmlDoc.DocumentNode.Descendants("h3");
            //         List<HtmlAgilityPack.HtmlNode> h3 = forms.ToList();

            forms = htmlDoc.DocumentNode.Descendants("p");
            List <HtmlAgilityPack.HtmlNode> p = forms.ToList();

//            forms = htmlDoc.DocumentNode.Descendants("p1");
//          List<HtmlAgilityPack.HtmlNode> p1 = forms.ToList();
        }