Exemple #1
0
        private IEnumerable <FreeDocument> GetDatas(IFreeDocument data)
        {
            var p = data[Column];

            if (p == null || Crawler == null)
            {
                return(new List <FreeDocument>());
            }
            var url    = p.ToString();
            var bufkey = url;
            var post   = data.Query(PostData);

            if (Crawler.Http.Method == MethodType.POST)
            {
                bufkey += post;
            }
            var htmldoc = buffHelper.Get(bufkey);

            if (htmldoc == null)
            {
                HttpStatusCode code;
                var            maxcount = 1;
                int.TryParse(data.Query(MaxTryCount), out maxcount);

                var count = 0;
                while (count < maxcount)
                {
                    var docs = Crawler.CrawlData(url, out htmldoc, out code, post);
                    if (HttpHelper.IsSuccess(code))
                    {
                        buffHelper.Set(bufkey, htmldoc);
                        return(docs);
                    }
                    Thread.Sleep(ErrorDelay);
                    count++;
                }
            }
            else
            {
                return(Crawler.CrawlData(htmldoc.DocumentNode));
            }
            return(new List <FreeDocument>());
        }