4
Reply

Reading HTML markups tag using C#

Abhimanyu K Vatsa

Abhimanyu K Vatsa

Feb 25 2012 4:48 AM
8.9k

I am developing a website that allows the users to enter a URL of the web page for promotions. I need some help on coding that would scan the given URL and downloads all HTML Markups placed inside a <div class="mainBlogData">scan me, I'm html markup</div>

Here is the concept I'm using

    protected void ScanLinks(string url)

    {

        WebClient client = new WebClient();

        string html = client.DownloadString(url);

 

        HtmlTag tag;

        HtmlParser parse = new HtmlParser(html);

        while (parse.ParseNext("div", out tag))   //need to modify here

        {

            string htmlMarkups;

            if (tag.Attributes.TryGetValue("class", out htmlMarkups))  //and here

            {

                TextBox2.Text = htmlMarkups;

            }

        }

    }

 

What changes I need to make in above coding to rid out. Please suggest its alternative way also.


Answers (4)