Exemplo n.º 1
0
        public static Subtitle getNovelSubtitle(string ncode, string html)
        {
            var htmlDoc = new HtmlAgilityPack.HtmlDocument();

            htmlDoc.LoadHtml(html);

            var dd = htmlDoc.DocumentNode.SelectNodes(@"//dd[@class=""subtitle""]/a")
                     .Select(x => new
            {
                Url   = x.Attributes["href"].Value.Trim(),
                Title = x.InnerText.Trim(),
            }).ToList().FirstOrDefault();
            var ret = new Subtitle();

            ret.Url     = dd.Url;
            ret.Title   = dd.Title;
            ret.Upddate = htmlDoc.DocumentNode.SelectNodes(@"//dt[@class=""long_update""]")
                          .Select(x => x.InnerText.Trim())
                          .ToList().FirstOrDefault().Substring(0, 16);
            var pageSplit = ret.Url.Split('/');

            ret.Id   = int.Parse(pageSplit[2]);
            ret.Html = HtmlMng.getNovel(ncode, pageSplit[2]);

            var subhtmlDoc = new HtmlAgilityPack.HtmlDocument();

            subhtmlDoc.LoadHtml(ret.Html);
            ret.Capter = subhtmlDoc.DocumentNode.SelectNodes(@"//div[@class=""contents1""]/p[@class=""chapter_title""]")
                         .Select(x => x.InnerText).SingleOrDefault();
            return(ret);
        }
Exemplo n.º 2
0
        // [ → ※[#始め角括弧、1-1-46]
        // ] → ※[#終わり角括弧、1-1-47]
        // 〔 → ※[#始めきっこう(亀甲)括弧、1-1-44]
        // 〕 → ※[#終わりきっこう(亀甲)括弧、1-1-45]
        // | → ※[#縦線、1-1-35]
        // # → ※[#井げた、1-1-84]

        public static void getNovelInfo(string ncode)
        {
            using (var cn = new SQLiteConnection(DbMng.getConnectionString()))
            {
                cn.Open();
                cn.ChangePassword("");
                using (var trans = cn.BeginTransaction())
                {
                    var novelid = DbMng.getNovelId(ncode, cn);
                    var html    = HtmlMng.getNovel(ncode);

                    if (novelid < 0)
                    {
                        novelid = DbMng.addNovelList(ncode, html, cn);
                    }
                    else
                    {
                        DbMng.updateNovelList(novelid, html, cn);
                    }

                    var htmlDoc = new HtmlAgilityPack.HtmlDocument();
                    htmlDoc.LoadHtml(html);
                    DbMng.deleteSubtitleByNovelId(novelid, cn);

                    var articles = htmlDoc.DocumentNode
                                   .SelectNodes(@"//div[@class=""index_box""]/dl[@class=""novel_sublist2""]");
                    var i = 0;
                    foreach (var a in articles)
                    {
                        i++;

                        var htmldl = new HtmlAgilityPack.HtmlDocument();
                        htmldl.LoadHtml(a.InnerHtml);

                        var dd = htmldl.DocumentNode.SelectNodes(@"//dd[@class=""subtitle""]/a")
                                 .Select(x => new
                        {
                            Url   = x.Attributes["href"].Value.Trim(),
                            Title = x.InnerText.Trim(),
                        }).ToList().FirstOrDefault();
                        var url     = dd.Url;
                        var title   = dd.Title;
                        var upddate = htmldl.DocumentNode.SelectNodes(@"//dt[@class=""long_update""]")
                                      .Select(x => x.InnerText.Trim())
                                      .ToList().FirstOrDefault().Substring(0, 16);
                        var pageSplit = url.Split('/');
                        var subhtml   = HtmlMng.getNovel(ncode, pageSplit[2]);
                        DbMng.addSubtitle(i, novelid, dd.Title, dd.Url, subhtml, upddate, cn);
                    }
                    trans.Commit();
                }
                cn.Close();
            }
        }