Esempio n. 1
0
        public void Fetch(Encoding encoding, bool inquiryLastModified, bool fromLocal, PathInfo localPathInfo)
        {
            string url = fromLocal ? localPathInfo.LocalFilePathFor(Uri) : Uri.AbsoluteUri;

            WebRequest request = WebRequest.Create(url);

            using (WebResponse response = request.GetResponse())
            {
                this.ContentType = response.ContentType;

                if (inquiryLastModified)
                {
                    if (fromLocal)
                    {
                        FileInfo fi = new FileInfo(url);
                        this.SavedDate = fi.LastWriteTime;
                    }
                    else
                    {
                        this.SavedDate = (response as HttpWebResponse).LastModified;
                    }
                }
            }

            if (this.ContentType.Contains("text") || fromLocal)
            {
                HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
                this.htmlDocument = new HtmlAgilityPack.HtmlDocument();

                if (encoding == null)
                {
                    web.AutoDetectEncoding = true;
                    htmlDocument           = web.Load(url);
                }
                else
                {
                    web.AutoDetectEncoding = false;
                    web.OverrideEncoding   = encoding;
                    htmlDocument           = web.Load(url);
                }

                this.TitleElement = this.GetTitleElement(this.htmlDocument);
                this.H1Element    = this.GetH1Element(this.htmlDocument);
            }
        }