예제 #1
0
 public static Site CreateSite(SiteType siteType, string basePage, string section="")
 {
     Site site = null;
     switch (siteType)
     {
         case SiteType.GUARDIAN:
             site = new Guardian(basePage, section);
             break;
         case SiteType.REGISTER:
             site = new Register(basePage, section);
             break;
         case SiteType.INSIDER:
             site = new Insider(basePage, section);
             break;
         default:
             throw new NotImplementedException("Wrong site type");
     }
     return site;
 }
예제 #2
0
        public override bool GetContent(out string content)
        {
            HtmlDocument htmlDocument = GetPage(basePage + section);
            // Get headline
            HtmlNode headline = htmlDocument.DocumentNode
                .SelectSingleNode("//div[contains(@class, 'article_head')]/h1");
            string header = headline?.InnerText ?? "";
            // Get article
            var text = string.Join(
                Environment.NewLine,
                (from p in htmlDocument.DocumentNode
                    .SelectNodeList("//div[@id='body']/p")
                 select p.InnerText));

            content = header + Environment.NewLine + text;
            // Get multipage content
            HtmlNode newPage = htmlDocument.DocumentNode
                .SelectSingleNode("//div[@id='nextpage']/a[@href]");
            if (newPage != null)
            {
                Register nextPage = new Register(basePage, newPage.Attributes["href"].Value);
                string nextPageContent = null;
                nextPage.GetContent(out nextPageContent);
                content = content + Environment.NewLine + nextPageContent;
            }
            Console.WriteLine("Content length: {0}", content.Length);
            return content.Length >= SymbolLimit;
        }