当前位置: 首页>>代码示例>>C#>>正文


C# HtmlDocument.ExtractWrittenTime方法代码示例

本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.ExtractWrittenTime方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.ExtractWrittenTime方法的具体用法?C# HtmlDocument.ExtractWrittenTime怎么用?C# HtmlDocument.ExtractWrittenTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlAgilityPack.HtmlDocument的用法示例。


在下文中一共展示了HtmlDocument.ExtractWrittenTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

        public void Start(Database database)
        {
            var lastArticle = database.ExecuteReader<Article>("SELECT * FROM Article ORDER BY ArticleId DESC LIMIT 1");
            if (lastArticle.Count == 0)
            {
                _lastCrawledArticleId = 0;
            }
            else
            {
                _lastCrawledArticleId = lastArticle[0].ArticleId;
            }

            var lastArticleId = GetLastArticleId();
            while (true)
            {
                // crawling 해야 할 글 지정
                var nextArticleId = _lastCrawledArticleId + 1;

                // 웹사이트 주소 구성
                var targetUrl = MakeArticleUrl(CategoryId, nextArticleId);

                try
                {

                    // 웹사이트 긁기 - 5초 이후 timeout
                    var rawHtml = targetUrl.CrawlIt(Encoding.GetEncoding(51949), 5000);

                    // 원하는 내용 추출
                    var htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(rawHtml);

                    var article = new Article
                    {
                        CategoryId = CategoryId,
                        ArticleId = nextArticleId,
                        RawHtml = rawHtml,
                        CrawlingTime = DateTime.Now,
                    };

                    article.IsDeleted = htmlDoc.IsDeletedArticle();
                    if (!article.IsDeleted)
                    {
                        article.Author = htmlDoc.ExtractAutor();
                        article.WriteTime = htmlDoc.ExtractWrittenTime();
                        article.Title = htmlDoc.ExtractTitle();
                        article.Content = htmlDoc.ExtractContent();
                    }

                    // 데이터베이스에 저장
                    database.SyncData<Article>(article);
                }
                catch (Exception ex)
                {
                    LogHelper.Log(new Exception(targetUrl));
                    LogHelper.Log(ex);
                }

                // 최신 글인지 확인
                while (nextArticleId == lastArticleId)
                {
                    lastArticleId = GetLastArticleId();
                    if (nextArticleId == lastArticleId)
                    {
                        // 글이 없을 경우 스레드 10분간 휴식
                        Thread.Sleep(10 * 60 * 1000);
                    }
                }

                // 각 글을 crawling 한 후 3초간 휴식
                Thread.Sleep(3 * 1000);

                _lastCrawledArticleId++;
            }
        }
开发者ID:WhiteCandy,项目名称:Crawler,代码行数:74,代码来源:InvenCrawler.cs


注:本文中的HtmlAgilityPack.HtmlDocument.ExtractWrittenTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。