Exemplo n.º 1
0
        public ActionResult PageData(Site site)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", site));
            }

            else
            {
                var pageDataViewModel = new PageDataViewModel();
                //var siteHtmlAgility = new SiteHtmlAgility();
                ViewBag.SiteAddress = site.Url;

                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                pageDataViewModel.StreamBufferSize = _siteHtmlAgility.Load(site.Url);
                stopWatch.Stop();
                if (pageDataViewModel.StreamBufferSize == -1)
                {
                    return(RedirectToAction("Index", new { error = "The site entered is not accessible form this applicaton due to network restrictions. Please enter a different URL." }));
                }


                pageDataViewModel.TimeElapsed        = stopWatch.ElapsedMilliseconds;
                pageDataViewModel.ImageAttributeList = _siteHtmlAgility.ExtractImages();
                pageDataViewModel.SiteWordList       = _siteHtmlAgility.ExtractText();
                pageDataViewModel.FrequencyMap       = _siteHtmlAgility.ExtractFrequencyMap(pageDataViewModel.SiteWordList);


                return(View(pageDataViewModel));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult Images(string url)
        {
            var imgs = new List <string>();

            if (!string.IsNullOrWhiteSpace(url))
            {
                var siteLoad = _siteHtmlAgility.Load(url);
                if (siteLoad == -1)
                {
                    return(Ok(imgs));
                }


                foreach (var item in _siteHtmlAgility.ExtractImages())
                {
                    imgs.Add(item.Value);
                }
            }
            return(Ok(imgs));
        }