Exemple #1
0
        void GetNewsText(string url)
        {
            NReadabilityWebTranscoder TwebTranscoder = new NReadability.NReadabilityWebTranscoder();
            bool   b;
            string detail;


            string page = TwebTranscoder.Transcode(url, DomSerializationParams.CreateDefault(), out b, out detail);


            if (b)
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(page);



                var    body  = doc.DocumentNode.SelectSingleNode("//div[@id='readInner']").InnerText;
                string title = doc.DocumentNode.SelectSingleNode("//title").InnerText;


                richTextBox1.Text = title.Trim();
                richTextBox2.Text = detail.Trim();
                richTextBox3.Text = body.Trim();
            }
        }
        public void Serializer_removes_viewport_meta_element_if_DontIncludeMobileSpecificElements_is_true()
        {
            // arrange
            const string htmlContent = "<html><head><meta name=\"viewport\" content=\"width=1100\" /></head><body></body></html>";

            var xDocument = _sgmlDomBuilder.BuildDocument(htmlContent);

            var domSerializationParams =
                new DomSerializationParams
            {
                DontIncludeMobileSpecificMetaElements = true,
            };

            // act
            string serializedHtmlContent =
                _sgmlDomSerializer.SerializeDocument(xDocument, domSerializationParams);

            // assert
            AssertViewportMetaElementPresence(serializedHtmlContent, false);
        }
        public void Serializer_adds_HandheldFrienly_meta_element_if_DontIncludeMobileSpecificElements_is_false()
        {
            // arrange
            const string htmlContent = "<html><head></head><body></body></html>";

            var xDocument = _sgmlDomBuilder.BuildDocument(htmlContent);

            var domSerializationParams =
                new DomSerializationParams
            {
                DontIncludeMobileSpecificMetaElements = false,
            };

            // act
            string serializedHtmlContent =
                _sgmlDomSerializer.SerializeDocument(xDocument, domSerializationParams);

            // assert
            AssertHandheldFriendlyMetaElementPresence(serializedHtmlContent, true);
        }
        public void Serializer_adds_content_type_meta_element_if_DontIncludeContentTypeMetaElement_is_false()
        {
            // arrange
            const string htmlContent = "<html><head></head><body></body></html>";

            var xDocument = _sgmlDomBuilder.BuildDocument(htmlContent);

            var domSerializationParams =
                new DomSerializationParams
            {
                DontIncludeContentTypeMetaElement = false,
            };

            // act
            string serializedHtmlContent =
                _sgmlDomSerializer.SerializeDocument(xDocument, domSerializationParams);

            // assert
            AssertContentTypeMetaElementPresence(serializedHtmlContent, true);
        }
        public void Serializer_adds_HandheldFrienly_meta_element_if_DontIncludeMobileSpecificElements_is_false()
        {
            // arrange
              const string htmlContent = "<html><head></head><body></body></html>";

              var xDocument = _sgmlDomBuilder.BuildDocument(htmlContent);

              var domSerializationParams =
            new DomSerializationParams
              {
            DontIncludeMobileSpecificMetaElements = false,
              };

              // act
              string serializedHtmlContent =
            _sgmlDomSerializer.SerializeDocument(xDocument, domSerializationParams);

              // assert
              AssertHandheldFriendlyMetaElementPresence(serializedHtmlContent, true);
        }
        public void Serializer_adds_generator_meta_element_if_DontIncludeGeneratorMetaElement_is_false()
        {
            // arrange
              const string htmlContent = "<html><head></head><body></body></html>";

              var xDocument = _sgmlDomBuilder.BuildDocument(htmlContent);

              var domSerializationParams =
            new DomSerializationParams
            {
              DontIncludeGeneratorMetaElement = false,
            };

              // act
              string serializedHtmlContent =
            _sgmlDomSerializer.SerializeDocument(xDocument, domSerializationParams);

              // assert
              AssertGeneratorMetaElementPresence(serializedHtmlContent, true);
        }
        private string getcontent(string url)
        {
            var    t = new NReadability.NReadabilityWebTranscoder();
            bool   b;
            string detail = "";
            string page   = t.Transcode(url, DomSerializationParams.CreateDefault(), out b, out detail);

            if (b)
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(page);


                // var imgUrl = doc.DocumentNode.SelectSingleNode("//meta[@property='og:image']").Attributes["content"].Value;
                var dd = doc.DocumentNode.SelectSingleNode("//div[@id='readInner']").InnerText;
                var tt = doc.DocumentNode.SelectSingleNode("//title").InnerText;
                richTextBox2.Text = detail;
                richTextBox1.Text = dd;
                return(dd);
            }
            return("");
        }
        public void Serializer_removes_viewport_meta_element_if_DontIncludeMobileSpecificElements_is_true()
        {
            // arrange
              const string htmlContent = "<html><head><meta name=\"viewport\" content=\"width=1100\" /></head><body></body></html>";

              var xDocument = _sgmlDomBuilder.BuildDocument(htmlContent);

              var domSerializationParams =
            new DomSerializationParams
            {
              DontIncludeMobileSpecificMetaElements = true,
            };

              // act
              string serializedHtmlContent =
            _sgmlDomSerializer.SerializeDocument(xDocument, domSerializationParams);

              // assert
              AssertViewportMetaElementPresence(serializedHtmlContent, false);
        }