コード例 #1
0
ファイル: Form1.cs プロジェクト: chromos33/Git
 private void HTMLLightNovelLinkParse(List<Webpage> pages)
 {
     LightNovelAvailableField.Items.Clear();
     if (pages.Count > 0)
     {
         foreach(Webpage item in pages)
         {
             HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
             doc.LoadHtml(item.html);
             var data = from tr in doc.DocumentNode.Descendants("div") where tr.Id.ToString() == "Label1" select tr;
             HtmlAgilityPack.HtmlDocument innerhtml = new HtmlAgilityPack.HtmlDocument();
             foreach(var innterhtmldata in data)
             {
                 innerhtml.LoadHtml(innterhtmldata.InnerHtml);
             }
             var VNlinks = from tr in innerhtml.DocumentNode.Descendants("a") select tr.Attributes["href"];
             var VNTitles = from tr in innerhtml.DocumentNode.Descendants("a") select tr;
             for(int i = 0; i< VNlinks.Count() && i< VNTitles.Count();i++)
             {
                 if(!VNTitles.ToArray()[i].InnerHtml.ToString().Contains("<img"))
                 {
                     LightNovel tempnovel = new LightNovel(VNlinks.ToArray()[i].Value.ToString(), VNTitles.ToArray()[i].InnerHtml.ToString());
                     LightNovelAvailableField.Items.Add(tempnovel.Title.ToString());
                     lightnovels.Add(tempnovel);
                 }
             }
             innerhtml = null;
             doc = null;
         }
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: chromos33/lightnovelparser
        private void HTMLLightNovelLinkParse(List<Webpage> pages)
        {
            LightNovelAvailableField.Items.Clear();
            if (pages.Count > 0)
            {
                foreach(Webpage item in pages)
                {
                    #region japtem
                    if(item.link.Contains("japtem"))
                    {
                        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                        doc.LoadHtml(item.html);
                        var data = from tr in doc.DocumentNode.Descendants("div") where tr.Id.ToString() == "Label1" select tr;
                        HtmlAgilityPack.HtmlDocument innerhtml = new HtmlAgilityPack.HtmlDocument();
                        foreach (var innterhtmldata in data)
                        {
                            innerhtml.LoadHtml(innterhtmldata.InnerHtml);
                        }
                        var VNlinks = from tr in innerhtml.DocumentNode.Descendants("a") select tr.Attributes["href"];
                        var VNTitles = from tr in innerhtml.DocumentNode.Descendants("a") select tr;
                        for (int i = 0; i < VNlinks.Count() && i < VNTitles.Count(); i++)
                        {
                            if (!VNTitles.ToArray()[i].InnerHtml.ToString().Contains("<img"))
                            {
                                LightNovel tempnovel = new LightNovel(VNlinks.ToArray()[i].Value.ToString(), VNTitles.ToArray()[i].InnerHtml.ToString());
                                LightNovelAvailableField.Items.Add(tempnovel);
                            }
                        }
                        innerhtml = null;
                        doc = null;
                    }
                    #endregion
                    #region baka-tsuki
                    if (item.link.Contains("baka-tsuki"))
                    {
                        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                        doc.LoadHtml(item.html);
                        var data = doc.DocumentNode.Descendants("div").Where(firstquery => firstquery.Attributes["class"] != null).Where(secondquery => secondquery.Attributes["class"].Value.Contains("mw-content-ltr")).Select(thirdquery => thirdquery.Descendants("a").Where((fourthquery => thirdquery.Attributes["Class"] != null)));
                        //var data = from tr in doc.DocumentNode.Descendants("div") where tr.Attributes["class"] != null select tr;
                        foreach (var dataitem in data)
                        {
                            foreach(var linkitem in dataitem)
                            {
                                if(!(linkitem.InnerHtml.ToLower().Contains("baka-tsuki") || linkitem.InnerHtml.ToLower().Contains("teaser project list")))
                                {
                                    LightNovel tempnovel = new LightNovel("https://www.baka-tsuki.org" + linkitem.Attributes["href"].Value, linkitem.InnerHtml);
                                    LightNovelAvailableField.Items.Add(tempnovel);
                                }
                            }

                        }
                    }
                    #endregion

                }
            }
        }