Ejemplo n.º 1
0
        //9.4重构ReadHtmlAndUpdateDicAsync方法,部分工作由Scanner的解析框架完成
        private async ValueTask UpdateDicByCatalogHtmlAsync(string url)
        {
            var ContentInfos = await Scanner.GetCatalogAsync(url);

            Regex latestChapter = new Regex("(?<=<a href=\"/\\d*/)(.*?html).*?(?<=>)(\\d*)(?=、.*?)");

            var results = new List <Match>();

            //<a href="/23609/72550175.html">735、青春、理想和现实</a>
            foreach (string item in ContentInfos)
            {
                try
                {
                    results.Add(latestChapter.Matches(item).First());
                }
                //正则出错的时候不能够扔出来错误的
                catch { }
            }
            foreach (Match item in results)
            {
                try
                {
                    dic.Add(int.Parse(item.Groups[2].Value), item.Groups[1].Value);
                }
                catch { }
            }
        }