Example #1
0
        private static bool ProcessCategory(string content)
        {
            try
            {
                JavDataBaseManager.DeleteCategory();

                var m = Regex.Matches(content, categoryPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);

                foreach (Match item in m)
                {
                    Category c = new Category
                    {
                        Url  = prefix + categoryPrefix + item.Groups[1].Value + postfix,
                        Name = item.Groups[2].Value
                    };

                    Console.WriteLine(string.Format("Get category {0}, URL {1}", c.Name, c.Url));
                    JavDataBaseManager.InsertCategory(c);
                }
            }
            catch (Exception e)
            {
                _logger.WriteExceptionLog("", string.Format("Process category error {0}", e.ToString()));
                return(false);
            }

            return(true);
        }
Example #2
0
        private static Dictionary <string, string> GetJavCategory()
        {
            Dictionary <string, string> genreDic = new Dictionary <string, string>();

            int times    = 1;
            int maxTimes = 3;

            //最大重试3次
            while (times <= maxTimes && (cc == null || cc.Count < 3))
            {
                GetJavCookie();
                times++;

                if (cc != null && cc.Count >= 3)
                {
                    break;
                }
            }

            if (times < 4 && cc != null)
            {
                //获取分类, 不会过期也不需要多线程
                var htmlRes = HtmlManager.GetHtmlWebClient("http://www.javlibrary.com/cn/", "http://www.javlibrary.com/cn/genres.php", cc, false);

                if (htmlRes.Success)
                {
                    HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                    htmlDocument.LoadHtml(htmlRes.Content);

                    var genrePath = "//div[@class='genreitem']";

                    var genreNodes = htmlDocument.DocumentNode.SelectNodes(genrePath);

                    foreach (var node in genreNodes)
                    {
                        var aTagHref  = "http://www.javlibrary.com/cn/" + node.ChildNodes[0].Attributes["href"].Value.Trim();
                        var aTagTitle = node.ChildNodes[0].InnerText.Trim();

                        if (!JavDataBaseManager.HasCategoryByName(aTagTitle))
                        {
                            JavDataBaseManager.InsertCategory(new Category
                            {
                                Name = aTagTitle,
                                Url  = aTagHref
                            });
                        }

                        if (!genreDic.ContainsKey(aTagHref))
                        {
                            genreDic.Add(aTagHref, aTagTitle);

                            Console.WriteLine("加入分类 " + aTagHref);
                        }
                    }
                }
            }

            return(genreDic);
        }